Here is the code I’m using for a physics based fps controller. It moves using the MovePosition in RigidBody. The problem with it right now is that w moves you up and not forward. can anyone fix this?
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody rb;
public float movementSpeed = 1f;
Vector3 movement;
// Start is called before the first frame update
void Start()
{
rb = this.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
}
void FixedUpdate()
{
moveCharacter(movement);
}
void moveCharacter(Vector3 direction)
{
// Convert direction into Rigidbody space.
direction = rb.rotation * direction;
rb.MovePosition(rb.position + direction * movementSpeed * Time.fixedDeltaTime);
}
}