🌐 Have you found the videos Helpful and Valuable? ❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
This was a well made explanation what transform component does. Having developed a few school projects in unity i was not aware of the local component part. Good reminder on that for me. Thank you for your hard work.
Yes, i couldn't agree more. I started using unity recently and suddenly saw the Ad's and thank god i did. Great work Code monkey will be anticipating your next videos.
@@CodeMonkeyUnity I have imported some assets and took some prefabs from there and I saw that the positions of the prefabs aren't (0, 0, 0) I tried to reset the positions of the prefabs but I can't it doesn't allow me to do that, is there a way to change it bcs the position of the Z axis is -1.96 but it needs to be 0 so that it is on my terrain and not below the terrain?
@@francek3892 Why can't you reset the position on the prefabs? You should be able to edit the position to anything you want Are you talking about creating them through code with Instantiate() ? The second parameter is the position
The Unity Api says "you should only apply absolute values, not increment them" for the transform.eulerAngles. Do I misunderstand the description, or is the shown example not recommended?
Hi I really like these types of videos where you explain how things work rather than "heres a code, copy it into your project", that I found in most of tutorials. I have to ask the "ChildTransform" is preset input? Also how would you handle situation where you got 2 or more children for that object. Lets say you got Player with weapon as 1st child and camera as 2nd.
What do you mean by preset input? The "ChildTransform" is just the name that I set on the child transform, it can be any name. You can have as many children as you want. You could have a Player game object and inside two children, a PlayerSprite and a Camera.
@@CodeMonkeyUnity see this is the problem. You put the code on the screen, but are not explaining it. If you make a beginner video, you need to explain it as if we know nothing.
What line are you referring to? transform.position = transform.position + new Vector3(0.01f, 0, 0) ? Sure you can do it many ways Vector3 newPosition = transform.position + new Vector3(0.01f, 0, 0); transform.position = newPosition; Or you could do transform.position += new Vector3(0.01f, 0, 0);
Hey, I know this is a bit old, but I had a question while I was watching the video. When you use the code to manipulate the rotation, the child object rotates around the parent object, treating the parent’s pivot like its own pivot. Is there a way to keep the parent-child relation, but prevent the child from rotating around the parent? That way they could still move in the line together, but just rotate in their own circles, rather than make one big one?
I'm not sure I understand, if you want to rotate just the child along the child axis then you can modify the child.localEulerAngles or child.localPosition Alternatively mabye you can unparent the child, move it, then re-parent it
I know this is 4 months late but something I could think of is storing the child's world rotation in a separate variable just before you transform the parent, and then immediately after apply the rotation back on to it? but this doesn't really sound like the best solution
When I put transform.position = transform. position + new Vector3(0.01f, 0,0); , my spritedid not move at all but when I set it in transform.position = transform. position + new Vector3(0.07f, 0,0); it moves I don't get it why plus i did exactly at 8:11 but i got an error which is NullReferenceException:object reference not set to an instance of an object ,don't know how to fix it.
Both those lines will move the transform, moving 0.07f units imply moves more than 0.01f If you're getting NullReferenceException on the line Debug.Log(childTransform.localPosition); then it means you have childTransform set to null. The variable is assigned in the previous line which does a transform.Find("ChildTransform"); so make sure the game object does have a child and the name is exactly "ChildTransform"
do you have to have like notepad+ in order to write scripts? or is it a setting thing? i started with a tutorial so i dont know if i need to "take off" the training wheels?
Code Monkey I appreciate that. I am doing this on a custom computer, and after rigorous googling I found that visual studio would’ve come pre installed if I didnt mess around with my install! Definitely subscribing your videos are more than helpful!
Thanks for the tutorial! Do you know if there's a way to change the movement direction based on a changing direction? I have a arrow gun that rotates to face my player but I have no idea how to make the arrows that shoot out shoot in the direction of my player if that makes any sense 😅
I have a question. There is a unit, the rotate character engine. I want to control this with keys, for example, when it is stationary, it returns when the key is pressed. GetKey commands don't work by the way. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Rotate : MonoBehaviour { public float RotationSpeed = 1f; private void Start() {
@@CodeMonkeyUnity Yes, that script attached to a game object, I want it to make a continuous rotation movement when I press "I" and then pull up. After that when I press "K" and then pull up, my gameobject must stop.
Unity keeps throwing compiler errors at me and Visual Studio won't pick up any of the function calls. Transform and debug just aren't registering to it and I'm not sure why. I made sure my code was identical to yours. I'm missing something I guess, but I have no idea what.
What compiler errors are you getting? Transform and Debug aren't being recognized in Visual Studio? Make sure you have the Visual Studio extension "Visual Studio Tools for Unity"
I don't think you can directly set the sprite in the constructor. The best way in terms of performance is: GameObject gameObject = new GameObject("mySprite", typeof(SpriteRenderer)); gameObject.GetComponent().sprite = mySprite;
Thanks! I just want to ask how do you get these tips for the code from Visual Studio. Mine doesn't work with the Unity commands such as transform or Time.time etc. Any help?
Hello I know this video is older and my question might not get answered, but I've noticed that since the transform function changes the position, scale, or rotation instantly. which could cause objects to just phase through it. but I want to transform an object the same way the inspector does it. here is my problem, its not the exact situation but ill simplify it. imagine a mesh collider wall that gets transformed to slide in a direction and what I want it to do is push on objects that it runs into and keep pushing them, just like how it would work if you just clicked on the X, Y, or Z values in the inspector and dragged them. but instead it just phases through all of the objects, even with a Lerp. but If I were to transform using the inspector, it does work exactly how I want it to. for the real situation that I am suffering through, I have a bunch of free floating "particles" or just spheres inside of a giant sphere, the big sphere has inverted normals so that the walls of the collider face the inside, not allowing anything to escape the inside of the sphere. I want to be able to scale the sphere up and down so that the particles inside of it would be forced to go to the center of the sphere, but I dont really want to add a force to the particles because every one of them already have a bunch of force calculations so they can attract and repel from each other
How thick is your wall? If it's super thin then it might cause issues but if it has enough thickness then it should work. As long as the distance for moving inside is shorter than moving outside the particle should move inside. Remember how the collider doesn't have to match the visual perfectly, you can make a thin wall visual with a thicker collider That's really it, changing it in the inspector or through code should have the same result, although when dealing with physics and scaling colliders things can become weird, the physics system does not like changing scales, if possible move the object instead of scaling.
@@CodeMonkeyUnity yeah, I'm going to make the particles take the radius of the circle and then use that to move the particles in and out of the center, thank you edit: also yeah I think the collider is infinitely thin
hello every body, i have a question in my mind for a long time and i will ask it here. what is difference between get the transform from a GameObject variable or Transform variable? i know you cant get a transform from GameObjects so why should i use Transform?
What do you mean "you cant get a transform from GameObjects"? if you have a GameObject you can get the Transform with gameObject.transform And if you have a Transform you can get the GameObject with transform.gameObject All Game Objects must have a Transform and all Transforms must be attached to a Game Object
In the final part of your tutorial, you don't see any difference in value between "Debug.Log (childTransform.localPosition);" and "Debug.Log (childTransform.position);" why ?
Preventing hacking is extremely difficult, if you're making a small game I would say don't bother. Giant companies like EA and Activision spend millions trying to stop it and there's always hackers.
Im struggling to make the child gameobject occupy the position of the parent object. I'm attempting to make one gameobject switch with another gameobject, but occupy the position of the previous gameobject. What do u do? This is in 3D btw.
@@CodeMonkeyUnity thanks for the insight. So, if I write my code something like: gameobject2.transform. position = gameobject1.transform. localposirion = new vector3(0, 0, 0)?
@@CodeMonkeyUnity so the code i ended up with was: Void update If(whichAvatarIsOn >=0) Transform. Localposition = new vector3(0, 0, 0); The other gameobjects are loading, but not where the avatar was.
Local space uses a specific point as the center, it's like when you sit in a moving car, you don't see you the car moving, but in reality you are moving with the car, that's local space
Hello. In to thank you to all the lessons to provided. But there is a problem is repeated lessons targeted for beginners, in fact brackeys channel and other channels discussed the basics of unity significantly there is no need to re-explained here. Just wish to be there lessons explain how to make a game. Or algorithms and other things like that. Thank you, abd sorry for my language.
Unity's objects take in Vector3s (transform.position, transform.localScale) However a Vector2 gets automatically cast into a Vector3 when you try to assign it so you can work with Vector2's only if you want and Unity will handle the conversion.
@@CodeMonkeyUnity please where to download extension that autocomplete those codes its really hard to type exectly the same as u without it i dont say it is impossible but its time consuming pls help
Way too brief. It would be much more useful if you went in to detail of coding examples and explanations. Very hard to find something like this for transform. Everyone is doing this with multiplying the values/variables together and it doesn't make any sense to me why what is written in the code is changing what is happening on the screen.
@@CodeMonkeyUnity more explanation of what people are doing in the code. Messing around with the unity UI is easy stuff, but I have been banging my head against the wall for 4 days trying to get things like shooting a bullet from an object that changes angles and the way that works in code makes no sense to me. Also things like making objects rotate to look at other objects automatically. Other examples I can't think about right now. It may be a simple thing but nobody is really explaining it like it that way.
🌐 Have you found the videos Helpful and Valuable?
❤️ Support on Patreon www.patreon.com/unitycodemonkey or get the Game Bundle unitycodemonkey.com/gamebundle.php
This was a well made explanation what transform component does. Having developed a few school projects in unity i was not aware of the local component part. Good reminder on that for me. Thank you for your hard work.
Thank you for advertising ...I found out an awesome channel
Glad you like what you see!
Yes, i couldn't agree more. I started using unity recently and suddenly saw the Ad's and thank god i did.
Great work Code monkey will be anticipating your next videos.
Yes
thanks a lot again. I code on a daily basis, but unity and its own classes and references get me every time i try it. Thanks for making things clear!
Glad the video helped!
@@CodeMonkeyUnity I have imported some assets and took some prefabs from there and I saw that the positions of the prefabs aren't (0, 0, 0) I tried to reset the positions of the prefabs but I can't it doesn't allow me to do that, is there a way to change it bcs the position of the Z axis is -1.96 but it needs to be 0 so that it is on my terrain and not below the terrain?
@@francek3892 Why can't you reset the position on the prefabs? You should be able to edit the position to anything you want
Are you talking about creating them through code with Instantiate() ? The second parameter is the position
omfgugfqflic, i spent almost an hour trying to understand the scale of unity. THX
I thought I was gonna know all this already and I still learned something!
thanks A lot your a real helper ❤❤❤
Awesome, thanks! Please more 2D tips and tricks!
Very easy to understand for beginners.
Your channel is exactly what I needed! Thank you for this
Love your work, mate! Thanks for opening the doors to Unity for many of us :)
I cant believe I skipped these valuable lessons and jumped to high level codes
heh yup make sure you fully understand the basics!
Crystal clear.
Love you
Thanks for the video
you r the best
u really helped me
Awesome! Glad to hear it!
Code Monkey! , AWESOME JOB! Bravo!!, and may i say , Who Don't Wanna Learn By a Nerd Monkey??
Please make more videos to guide beginner like me
Thank you 😊
Thank you ! You really helped me !
is this the best explain of sprite render on RUclips ?
The Unity Api says "you should only apply absolute values, not increment them" for the transform.eulerAngles.
Do I misunderstand the description, or is the shown example not recommended?
Thank you this helped a lot!!
as always awesome
Hi I really like these types of videos where you explain how things work rather than "heres a code, copy it into your project", that I found in most of tutorials. I have to ask the "ChildTransform" is preset input? Also how would you handle situation where you got 2 or more children for that object. Lets say you got Player with weapon as 1st child and camera as 2nd.
What do you mean by preset input? The "ChildTransform" is just the name that I set on the child transform, it can be any name.
You can have as many children as you want. You could have a Player game object and inside two children, a PlayerSprite and a Camera.
@@CodeMonkeyUnity see this is the problem. You put the code on the screen, but are not explaining it. If you make a beginner video, you need to explain it as if we know nothing.
Awesome videos!!!
Thank you:)
very useful
nice job bro
thank you so much
hi, im using vs 2022 and unity 2022.
for some reason my code In c# doesn't recognize transform as an option
what do i do
Hello, I am brasilian and have you ever think to make a Portuguese channel for people that don’t understand English
5:22 You can also just do
transform.position += new Vector3(.01f, 0, 0);
awesome, Thank you .........
Nice!
Excelent, thank you.
So is " + new Vector3 " an alternative to creating a vector 3 variable and adding it to your Transform position?
What line are you referring to? transform.position = transform.position + new Vector3(0.01f, 0, 0) ?
Sure you can do it many ways
Vector3 newPosition = transform.position + new Vector3(0.01f, 0, 0);
transform.position = newPosition;
Or you could do
transform.position += new Vector3(0.01f, 0, 0);
@@CodeMonkeyUnity Yes, I'm referring to that. Thank you
Hey, I know this is a bit old, but I had a question while I was watching the video.
When you use the code to manipulate the rotation, the child object rotates around the parent object, treating the parent’s pivot like its own pivot.
Is there a way to keep the parent-child relation, but prevent the child from rotating around the parent? That way they could still move in the line together, but just rotate in their own circles, rather than make one big one?
I'm not sure I understand, if you want to rotate just the child along the child axis then you can modify the child.localEulerAngles or child.localPosition
Alternatively mabye you can unparent the child, move it, then re-parent it
@@CodeMonkeyUnity he wants to rotate the parent without affecting the child.
I know this is 4 months late but something I could think of is storing the child's world rotation in a separate variable just before you transform the parent, and then immediately after apply the rotation back on to it? but this doesn't really sound like the best solution
When I put transform.position = transform. position + new Vector3(0.01f, 0,0); , my spritedid not move at all but when I set it in transform.position = transform. position + new Vector3(0.07f, 0,0); it moves I don't get it why plus i did exactly at 8:11 but i got an error which is NullReferenceException:object reference not set to an instance of an object ,don't know how to fix it.
Both those lines will move the transform, moving 0.07f units imply moves more than 0.01f
If you're getting NullReferenceException on the line Debug.Log(childTransform.localPosition); then it means you have childTransform set to null.
The variable is assigned in the previous line which does a transform.Find("ChildTransform"); so make sure the game object does have a child and the name is exactly "ChildTransform"
@@CodeMonkeyUnity thank you! Your tutorial helps a lot
IS it important to use or learn c# to make games like this ??
Unity uses C# so yes, but you can also make games entirely with Visual Scripting ruclips.net/video/qAkeCDWgPVA/видео.html
@@CodeMonkeyUnity How ?
do you have to have like notepad+ in order to write scripts? or is it a setting thing? i started with a tutorial so i dont know if i need to "take off" the training wheels?
I use Visual Studio Community
Code Monkey I appreciate that. I am doing this on a custom computer, and after rigorous googling I found that visual studio would’ve come pre installed if I didnt mess around with my install! Definitely subscribing your videos are more than helpful!
Thanks for the tutorial! Do you know if there's a way to change the movement direction based on a changing direction? I have a arrow gun that rotates to face my player but I have no idea how to make the arrows that shoot out shoot in the direction of my player if that makes any sense 😅
You can calculate the direction vector and set transform.forward
Or you can use transform.LookAt();
I have a question. There is a unit, the rotate character engine. I want to control this with keys, for example, when it is stationary, it returns when the key is pressed. GetKey commands don't work by the way.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour
{
public float RotationSpeed = 1f;
private void Start()
{
}
void Update()
{
if (Input.GetKey(KeyCode.I))
transform.Rotate(new Vector3(0f, 1f, 0f).normalized * RotationSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.K))
transform.Rotate(new Vector3(0f, 0f, 0f).normalized * RotationSpeed * Time.deltaTime);
}
}
Everything there should work, is that script attached to a game object?
@@CodeMonkeyUnity Yes, that script attached to a game object,
I want it to make a continuous rotation movement when I press "I" and then pull up.
After that when I press "K" and then pull up, my gameobject must stop.
That is a propeller of engine.
eulerAngles is pronounced "oiler angles" just FYI. Thanks for the great tutorials.
Unity keeps throwing compiler errors at me and Visual Studio won't pick up any of the function calls. Transform and debug just aren't registering to it and I'm not sure why. I made sure my code was identical to yours. I'm missing something I guess, but I have no idea what.
What compiler errors are you getting? Transform and Debug aren't being recognized in Visual Studio? Make sure you have the Visual Studio extension "Visual Studio Tools for Unity"
@@CodeMonkeyUnity Ah, I never installed that. Thanks
how to set the sprite renderer to a certain sprite, when initializing it?
I don't think you can directly set the sprite in the constructor.
The best way in terms of performance is:
GameObject gameObject = new GameObject("mySprite", typeof(SpriteRenderer));
gameObject.GetComponent().sprite = mySprite;
Thanks!
I just want to ask how do you get these tips for the code from Visual Studio. Mine doesn't work with the Unity commands such as transform or Time.time etc.
Any help?
On the Unity preferences set your IDE and install Visual Studio Tools for Unity
@@CodeMonkeyUnity Thank you!
@@CodeMonkeyUnity I still have the same problem, even though I have done all of this before I started coding... any other piece of advice please?
how do i make limits of scale
Hello I know this video is older and my question might not get answered, but I've noticed that since the transform function changes the position, scale, or rotation instantly. which could cause objects to just phase through it. but I want to transform an object the same way the inspector does it.
here is my problem, its not the exact situation but ill simplify it.
imagine a mesh collider wall that gets transformed to slide in a direction and what I want it to do is push on objects that it runs into and keep pushing them, just like how it would work if you just clicked on the X, Y, or Z values in the inspector and dragged them. but instead it just phases through all of the objects, even with a Lerp.
but If I were to transform using the inspector, it does work exactly how I want it to.
for the real situation that I am suffering through, I have a bunch of free floating "particles" or just spheres inside of a giant sphere, the big sphere has inverted normals so that the walls of the collider face the inside, not allowing anything to escape the inside of the sphere. I want to be able to scale the sphere up and down so that the particles inside of it would be forced to go to the center of the sphere, but I dont really want to add a force to the particles because every one of them already have a bunch of force calculations so they can attract and repel from each other
How thick is your wall? If it's super thin then it might cause issues but if it has enough thickness then it should work. As long as the distance for moving inside is shorter than moving outside the particle should move inside. Remember how the collider doesn't have to match the visual perfectly, you can make a thin wall visual with a thicker collider
That's really it, changing it in the inspector or through code should have the same result, although when dealing with physics and scaling colliders things can become weird, the physics system does not like changing scales, if possible move the object instead of scaling.
@@CodeMonkeyUnity yeah, I'm going to make the particles take the radius of the circle and then use that to move the particles in and out of the center, thank you
edit: also yeah I think the collider is infinitely thin
hello every body, i have a question in my mind for a long time and i will ask it here.
what is difference between get the transform from a GameObject variable or Transform variable?
i know you cant get a transform from GameObjects so why should i use Transform?
What do you mean "you cant get a transform from GameObjects"?
if you have a GameObject you can get the Transform with gameObject.transform
And if you have a Transform you can get the GameObject with transform.gameObject
All Game Objects must have a Transform and all Transforms must be attached to a Game Object
How do you move a transformer of your object only one time without it moving every frame and without using the void start?
Store a float timer and count down on Update, do whatever you want when the timer elapses.
In the final part of your tutorial, you don't see any difference in value between "Debug.Log (childTransform.localPosition);" and "Debug.Log (childTransform.position);" why ?
If the parent is at 0, 0 then the localPosition will match position
@@CodeMonkeyUnity thank you very much
CAN YOU MAKE THESE GAMES ON SCRATCH
In need of help how do you make a unity android game immune to hacking
Preventing hacking is extremely difficult, if you're making a small game I would say don't bother.
Giant companies like EA and Activision spend millions trying to stop it and there's always hackers.
Im struggling to make the child gameobject occupy the position of the parent object. I'm attempting to make one gameobject switch with another gameobject, but occupy the position of the previous gameobject. What do u do?
This is in 3D btw.
If you set the transform.localPosition to Vector3(0,0,0) it will be on the exact position of the parent
@@CodeMonkeyUnity thanks for the insight.
So, if I write my code something like: gameobject2.transform. position = gameobject1.transform. localposirion = new vector3(0, 0, 0)?
@@CodeMonkeyUnity so the code i ended up with was:
Void update
If(whichAvatarIsOn >=0)
Transform. Localposition = new vector3(0, 0, 0);
The other gameobjects are loading, but not where the avatar was.
@@CodeMonkeyUnity fixed it. Thank you. I had an extra gameobject that was parent to what i thought was the parent.
Thanks again.
In the tutorial do you use a figure (sprite) where can I find it?
Ah, found. It was about downloading another project that contained it.
Can we make games in unity without using c#
Yes you can also make games entirely with Visual Scripting ruclips.net/video/qAkeCDWgPVA/видео.html
Whats is locel value (like whats us the difference)
Local space uses a specific point as the center, it's like when you sit in a moving car, you don't see you the car moving, but in reality you are moving with the car, that's local space
How can u make a reference to the child of the parent without using the name of the gameobj
You can make a public field or a [SerializeField] private and drag the reference directly
Someone help me
List targets
How to find this targets with tag...
Cycle through that list and use CompareTag()
Thanks Code Monkey.👍👍
How do i get an object to change from one form to another?
What do you mean by form? You can scale it with localScale or if you're using a SpriteRenderer just give it another Sprite.
@@CodeMonkeyUnity Its the latter, I meant changing it from one sprite to another.
Hello. In to thank you to all the lessons to provided. But there is a problem is repeated lessons targeted for beginners, in fact brackeys channel and other channels discussed the basics of unity significantly there is no need to re-explained here. Just wish to be there lessons explain how to make a game. Or algorithms and other things like that.
Thank you, abd sorry for my language.
What is the point of using vector3 on a 2D game?
Unity's objects take in Vector3s (transform.position, transform.localScale)
However a Vector2 gets automatically cast into a Vector3 when you try to assign it so you can work with Vector2's only if you want and Unity will handle the conversion.
GLOBAL - there's B inside... you're pronauncing BLOGOL... ehhh what's the reason? where do u come from?
I'm from Portugal so my accent might be a bit weird, I'm saying Global though, where are you hearing Blogol?
@@CodeMonkeyUnity It sounds like this. I will use to it. Np :)
Subtiles French ?
Please ^^
Bro help me It dont login when i try😪😪😪😪😪😪😪😪😪😪😪😪😪
On my website? Use the contact form to let me know your email and I'll look into it
why vector3? not vector2?
Unity is a 3D engine even if you're using it in 2D. You can use Vector2, Unity will automatically convert to Vector3
@@CodeMonkeyUnity please where to download extension that autocomplete those codes its really hard to type exectly the same as u without it i dont say it is impossible but its time consuming pls help
Pronounced 'Oiler' not 'You-ler'
Way too brief. It would be much more useful if you went in to detail of coding examples and explanations. Very hard to find something like this for transform. Everyone is doing this with multiplying the values/variables together and it doesn't make any sense to me why what is written in the code is changing what is happening on the screen.
What exactly would you like more detail on? The transform component is pretty simple, just holds parent/child relations and 3 Vector3's
@@CodeMonkeyUnity more explanation of what people are doing in the code. Messing around with the unity UI is easy stuff, but I have been banging my head against the wall for 4 days trying to get things like shooting a bullet from an object that changes angles and the way that works in code makes no sense to me. Also things like making objects rotate to look at other objects automatically. Other examples I can't think about right now. It may be a simple thing but nobody is really explaining it like it that way.
stop speaking like that
Like what?
@@CodeMonkeyUnity OMG you replied! Bro You have 500k Subs. I am sorry you are the best