movement with rigidbody

is there a movement script to allow you to move a rigidbody like you move a character controler? im trying to make a racing game without using to much of other peoples script :)

2 Answers

2

you could try something like this:

private float speed = some value;

void FixedUpdate()
{
   float horizontalInput = Input.GetAxis("Horizontal");
   float verticalInput = Input.GetAxis("Vertical");

   Vector3 a = transform.eulerAngles;

   if(horizontalInput > 0.1)
      transform.eulerAngles = new Vector3(a.x, a.y + (value * Time.Deltatime * 10), a.z);

   else if(horizontalInput < 0)
      transform.eulerAngles = new Vector3(a.x, a.y - (value * Time.Deltatime * 10), a.z);

   Vector3 moveDirection = new Vector3(verticalInput*speed,0,0);

   if(verticalInput > 0.1)
      rigidbody.AddRelativeForce(moveDirection,ForceMode.Acceleration);
}

Btw, this is C# code but it shouldn't be too hard to translate it to javaScript ;)

There are some fps scripts using rigidbody on the wiki. http://www.unifycommunity.com/

If you are looking for car physics you should get the car tutorial from the unity resources. That's a good starting point.

http://www.unifycommunity.com/wiki/index.php?title=PhysicsFPSWalker there's a link to a rigidbody fps walker :) (for those lazy people like me)

–