player movement not using rotation
i have a problem with my character movement. im making a first person game and when i use this code like this it doesnt move the character based on where hes facing. does anyone know how to fix this?
public float speed = 10.0f;
public float JumpForce = 200.0f;
private bool _grounded;
private Rigidbody rb;
Vector3 movement;
void Start ()
{
rb = gameObject.GetComponent<Rigidbody>();
}
void Update ()
{
}
void FixedUpdate()
{
movement.z = Input.GetAxis("Vertical");
movement.x = Input.GetAxis("Horizontal");
rb.velocity = movement * speed;
RaycastHit hit;
Ray jumpRay = new Ray(this.transform.position, Vector3.down);
if(Physics.Raycast(jumpRay,out hit, 1.0f))
{
if(hit.transform.tag == "Ground")
{
_grounded = true;
}
}
if ((Input.GetKeyDown(KeyCode.Space)) && _grounded)
{
rb.AddForce(Vector3.up * JumpForce);
_grounded = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Realistic ball left-right movement 0 Answers
Fixed Update randomly stops player rotation 0 Answers
Character Rotation 0 Answers
Arrow mechanic like soccer star 0 Answers