Unity/C# Challenge 41: Adding Velocity

Alec Oney
Oct 28, 2021

--

Challenge: Add velocity in our player controller

Currently, we are creating a new vector 3 based on the horizontal axis to get direction, and changing our player’s position based on that. As we are going to affect the physics of our game down the road, we want to separate out direction and speed. First, we create a variable “speed” (set to 5.0f) and update our movement code for our player:

now, our controller moves our player the speed we set * the direction of our horizontal axis:

--

--

No responses yet