- Home /
Move an object without Character Controller?
Is it possible to move an object without using a character controller or addForce but just by using the transform.Translate and transform.Rotate?I am new at this and I get stuck at this thing because I want to make an object move without using a character controller or the addForce to a rigidbody but just by scripting it.......the translation and rotation. Any help appreciated!
Answer by Loius · Aug 12, 2012 at 07:40 PM
Yes.
...
Fiiine. You certainly can. Are you having a specific issue? You can directly alter position/rotation through transform.position (a Vector3) and transform.rotation (a Quaternion). You can also set rotation by using tranform.forward, .right, and .up, but you can run into issues using those if you're looking around in 3D. Better to use Quaternion.LookRotation in that case.
For instance, this'll make an object move according to the Horizontal and Vertical axes set up in project settings, and the object will snap to face the direction it's moving.
var desiredMovement : Vector3 = Vector3( Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical") );
transform.position+= desiredMovement;
if ( desiredMovement.sqrMagnitude > 0 ) transform.forward = desiredMovement;