This question was
closed Feb 18, 2018 at 08:22 PM by
LinkUpGames for the following reason:
Found the solution myself.
Question by
LinkUpGames · Feb 18, 2018 at 07:56 PM ·
c#vector3charactercontroller
Normalized Vector3 doesn't allow for jumping?
Hey there, so I wanted to normalize my movement Vector3 form the CharacterController.Move in the scripting API. While the code works for normalizing the speed of movement on the x and the z. It also (from what I've gathered) normalizes the y axis. Jumping does not work at all and gravity is applied in a very janky slow downward movement. I think the solution is to only normalize the x and z movement and allow the y to remain un-normalized but I'm not exactly sure how. Any suggestions? Here is the code:
float h = Input.GetAxis( "Horizontal" );
float v = Input.GetAxis( "Vertical" );
if ( controller.IsGrounded )
{
if ( Input.GetButton( "Jump" ) )
{
moveDirection.Set( h, jumpSpeed, v );
}
else
{
moveDirection.Set( h, 0, v );
}
moveDirection = transform.TransformDirection( moveDirection );
moveDirection = moveDirection.normalized * ( groundSpeed * Time.deltaTime );
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move( moveDirection );
Comment