Unity 3d Tutorial – Puzzle Game – Part 3 – Player Movement – Rotate and Moving – longtnh
Next I will make this character move Open script, declare a new Vecter3 Naming it “m_DesiredForward” Set value for it Pass values Declare a new variable In this case, i don’t really need this variable, so keep 0f here Go back here, there is a new thing. I can drag to edit this value I need a new vecter3: mRotation So, declare it here Ok, i’ve just set “rotation” for character To make it move, i use OnAnimatorMove method It’s also a built-in method from Unity In this method, i set some info for character rigibody rename this variable Pass values to MovePosition method Set rotation for rigibody Check something To use OnAnimatorMove method, i have to change Update mode of Animator component to Animate Physics Search Unity Animate Physics for more detail Unity has explain here Check again Let’s try a test, Up, Down, Left, Right Rotating is Ok But my character does not move Let’s check the scripts Check my model property Something is not true Ok, i find out There are 2 type of moving animation The first type is position of the character change when run-animation animates In this case, the code should be like that The second type is position of the character does not change ok, comment the code and write detail info now, i’ll write the new one declare a new Vecter3 get current position of the character Set value for new position set character position to the new one this is a clear and detailed way i can write all in a line these are same this way is more detailed testing now Ok, my character moves Down, Left, Right…. It’s quite fast. So, change the speed It’s ok now Exit play mode and change this to 5 So, i’ve done the player movement. Thanks for watching. See you in the next video. Leave a like if it’s useful with you. Thanks!!!