slowing sideways velocity

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:

rigidbody.AddRelativeForce(new Vector3(sideWaysVelocity,0,0)*magnitude);

where the magnitude variable diminishes over a short period of time (snowboarding game, a bit of drift is desired).

My questions are:

1.) Is my assumption for the solution correct?

2.)how would I calculate relative sideways velocity to give me a float between -1 & 1?

It’s my first attempt at making a game, be gentle!

Lol! I had to type it all out to understand the problem. I just got this to work for me:

var xVelocity : float = transform.InverseTransformDirection(rigidbody.velocity).x;
	if (xVelocity != 0){
		if (!airBorne){
			rigidbody.AddRelativeForce(new Vector3(xVelocity,0,0)* -magnitude);
		}
	}

where the magnitude variable does NOT change and rather the xVelocity does!

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.

  1. 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.

  2. Input.GetAxis can return -1 or 1. Multiply that and your variable for force.