diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 174bfee..ddc9b74 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -250,6 +250,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ec5d582fdf544e84d8dff955464dd912, type: 3} m_Name: m_EditorClassIdentifier: + moveSpeed: 1 --- !u!1 &705507993 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Dobber.cs b/Assets/Scripts/Dobber.cs index 86f62e5..87cd91d 100644 --- a/Assets/Scripts/Dobber.cs +++ b/Assets/Scripts/Dobber.cs @@ -16,11 +16,13 @@ public class Dobber : MonoBehaviour void Awake() { + //i don't know why dose need to reference it's self but it's requiered to work playerControls = new PlayerControls(); //automatically find rigidbody in character rb = gameObject.GetComponent(); - //lock rotation or the rigidbody + //lock rotation of the rigidbody rb.constraints = RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX; + //here we enable controlls for Dobber character playerControls.DobberControls.Enable(); } @@ -35,6 +37,7 @@ public class Dobber : MonoBehaviour //this void assignes values to input virables void Inputs() { + //reading the Vector2 value and assigning it to moveHorizontal and moveVertical moveHorizontal = playerControls.DobberControls.Walk.ReadValue().x; moveVertical = playerControls.DobberControls.Walk.ReadValue().y; @@ -42,8 +45,9 @@ public class Dobber : MonoBehaviour void Move() { - + //new Vector3 for calculating movement values Vector3 move = new Vector3(moveHorizontal * 100 * moveSpeed * Time.deltaTime, rb.velocity.y, moveVertical * 100 * moveSpeed * Time.deltaTime); + //here we apply the movement related to the rotation of player rb.velocity = transform.right * move.x + transform.up * move.y + transform.forward * move.z; }