I’m making a snowboarding game. When the user presses the “w” key, I speed up the snowboarder using this:
if (Input.GetKey(upKey)){
rigidbody.AddRelativeForce(new Vector3(0,0,1)*1000f);
}
When I turn the character, all that relative forwards velocity has now become sideways velocity. I assume that I need to apply some variant of this code in fixedUpdate over time:
If you turn the character his forward facing direction changes as well. In your first code you apply force in the Vector3.forward direction–that direction changes with your character if you rotate him.
The easiest way to get the movement you want (IMO, maybe one of the pros will have a better Idea) is to not turn him (but use the animations you want…) and also apply a force for the sideWaysVelocity. It’s about the illusion of turning and movement.
For your proposed solution, I think you’ll eventually implement a system where your forward velocity is modified by the length of time you’ve been going down hill (“speeding up”) and if your turning hard (Carving? To slow you down some). You’ll limit the gains on magnitude use Mathf.Clamp.
Input.GetAxis can return -1 or 1. Multiply that and your variable for force.