Question - How to move objects in unity
In unity, you can variously move an object.
In this blog, I'm going to discuss the two most easiest and common ways to move an object.
In this blog, I'm going to discuss the two most easiest and common ways to move an object.
1.Using Transform.
(Using only the transform of the object. In simple words, you don't have to add any additional component.)
(watch the above video if you don't know how to insert 3D objects)
In the above picture, you can see the object. Select the object and add a new C# script in it.
Now double click on the script and it will open.
Write these simple lines of codes, and you're ready to go.
(fig : 03)
Now if you hit the play button in Unity or press clt+P than the game will start. With the help of Arrow keys or W, A, S, D you can move the object.
(watch the above video for final result)
2.Using Rigidbody.
(This time we have to add rigidbody component to our object)
As you can see in the previous case, our object is flying in the air. It means that our object doesn't have any gravity.
So this time we are going to add a rigid body component to our object.
So this time we are going to add a rigid body component to our object.
Now if you play than you can move the object and also gravity will work, but the movement of the object will not going to be natural.
(watch the above video for how a rigid body react in unity)
So we have to change the script a little bit.
And also for better presentation, I changed the box object to a sphere.You can add the sphere with the same process shown in the first part.
(watch the above video for final result)
So this is how we can move objects in unity.
Thank You.
Comments
Post a Comment