Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity 2d platformer movement script rigidbody

float acceleration = grounded ? walkAcceleration : airAcceleration;
float deceleration = grounded ? groundDeceleration : 0;

// Update the velocity assignment statements to use our selected
// acceleration and deceleration values.
if (moveInput != 0)
{
	velocity.x = Mathf.MoveTowards(velocity.x, speed * moveInput, acceleration * Time.deltaTime);
}
else
{
	velocity.x = Mathf.MoveTowards(velocity.x, 0, deceleration * Time.deltaTime);
}
Source by roystan.net #
 
PREVIOUS NEXT
Tagged: #unity #platformer #movement #script #rigidbody
ADD COMMENT
Topic
Name
9+4 =