Hey there, I’m currently making an endless runner style game where you control a car. The car itself never moves on the z-axis, instead the road is sent towards the car. I have the car moving on just the x-axis using most of the script from the Space Shooter tutorial from the Unity website, however I’m having a bit of trouble.
Here is the code,
public class SimplePlayerControl : MonoBehaviour
{
public float speed;
public float turnAngle;
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rigidbody.velocity = movement * speed;
rigidbody.rotation = Quaternion.Euler (0.0f, rigidbody.velocity.x * turnAngle, 0.0f);
}
}
Now it’s almost working fine except when the car goes over jumps that it encounters, it comes down very slowly. I’m assuming it’s because of what I’ve defined with the new Vector3 (movement).
If I change the code to;
Vector3 movement = new Vector3 (moveHorizontal, -1.0f, 0.0f)
The car slams against the ground and doesn’t move on the x-axis very easily. Also when it goes over a jump it descends too quickly. I’d prefer it if it flew threw the air and had a bit of hang-time.
Is there anything I can replace in the code so the car doesn’t look to the new Vector3 for gravity, and instead uses the rigidBody mass?
Thanks for your time.