Search Unity

help change my script to work with rigidbody

Discussion in 'Scripting' started by DjAc!d, Nov 9, 2010.

  1. DjAc!d

    DjAc!d

    Joined:
    Aug 13, 2010
    Posts:
    18
    hey my current movement script is made to work with char controller, but the car cant rollover or anything, could someone please help me change it to work with rigid body

    Code (csharp):
    1. //moving around
    2. var speed = 3.0;
    3. var rotateSpeed = 3.0;
    4. //shooting
    5. var bulletPrefab:Transform;
    6.  
    7. function Update ()
    8.         {
    9.             var controller : CharacterController = GetComponent(CharacterController);
    10.             transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    11.             var forward = transform.TransformDirection(Vector3.forward);
    12.             var curSpeed = speed * Input.GetAxis ("Vertical");
    13.             controller.SimpleMove(forward * curSpeed);
    14.    
    15.      if(Input.GetButtonDown("Jump"))
    16.      {
    17.           var bullit = Instantiate(bulletPrefab, transform.Find("shootPoint").transform.position, Quaternion.identity);
    18.           bullit.tag = "Progectile";
    19.           bullit.rigidbody.AddForce(transform.forward * 3000);
    20.      }
    21.      
    22.  }
    23.  
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Rigidbodies and CharacterControllers generally don't play very well with each other so you should choose one approach or the other. If you want rigidbody physics, you will probably want to look at using wheel colliders. You might find the JCar script from the Unify wiki a good starting point and there is also a car tutorial available from the Unity website.