- Home /
Question by
Tolstyy · Jun 01, 2020 at 07:46 PM ·
movementrigidbodyanimationcurve
Player not moving even though input is working
So im trying to move my player using rigidbody.MovePosition and AnimationCurves to be able to have different speeds depending on axis. But it just doesn't move the debug log below is showing the speed at which the character should be moving at and yet it doesnt move. I have a collider as a child of the player and the rigidbody is set to unitys default settings except the rotation which is frozen.
public AnimationCurve speedByAngle = new AnimationCurve(new Keyframe(0, 1f), new Keyframe(90f, 0.5f), new Keyframe(180f, 0.5f));
float axisX = joystickInput.axis.x; // assuming this goes from -1 to 1
float axisY = joystickInput.axis.y; // assuming this goes from -1 to 1
// Create a direction vector directly from the input
Vector3 dir = new Vector3(axisX, 0, axisY).normalized;
// Now calculate the angle between forward and your move vector
// and use this to get the speed from the animation curve
float speed = speedByAngle.Evaluate(Vector3.Angle(dir, Vector3.forward));
Vector3 global = Player.instance.hmdTransform.TransformDirection(dir);
rb.MovePosition(Vector3.ProjectOnPlane(global, Vector3.up) * speed * Time.deltaTime);
Debug.Log("Speed: " + speed);
Comment