I cant seem to move, i have completed Episode 1+2 please help me

Updated on August 8, 2018 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on August 8, 2018

This is my code

PlayerController

using UnityEngine;

[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {

    [SerializeField]
    private float speed = 5f;
    [SerializeField]
    private float lookSensitivity = 3f;

    private PlayerMotor motor;

    void start ()
    {
        motor = GetComponent <PlayerMotor> ();
    }

    void update ()
    {
        //calculate movement velocity as a 3D vector
        float _xMov = Input.GetAxisRaw (Horizontal);
        float _zMov = Input.GetAxisRaw (Vertical);

        Vector3 _movHorizontal = transform.right * _xMov;
        Vector3 _movVertical = transform.forward * _zMov;

        //final movement vector
        Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;

        //apply movement
        motor.Move (_velocity);

        //Cauclate rotation as a 3D Vector: This is for <span style="font-style: italic; color: #888888;”>turning<span style=”font-style: italic; color: #888888;”> around<br />        float _yRot = Input.GetAxisRaw(Mouse X);

        Vector3 _rotation = new Vector3 (0f, _yRot, 0f) * lookSensitivity;

        //Apply<span style="font-style: italic; color: #888888;”> Roatation<br />        motor.Rotate(_rotation);

        //Cauclate camera rotation as a 3D Vector: This is for <span style="font-style: italic; color: #888888;”>turning<span style=”font-style: italic; color: #888888;”> around<br />        float _xRot = Input.GetAxisRaw(Mouse V);

        Vector3 _cameraRotation = new Vector3 (0f, _yRot, 0f) * lookSensitivity;

        //Apply Camera<span style="font-style: italic; color: #888888;”> Roatation<br />        motor.RotateCamera(_cameraRotation);

    }
     
}

PlayerMotor

using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour {

    [SerializeField]
    private Camera cam;

    private Vector3 velocity = Vector3.zero;
    private Vector3 rotation = Vector3.zero;
    private Vector3 cameraRotation = Vector3.zero;

    private Rigidbody rb;

    void start ()
    {
        rb = GetComponent <Rigidbody> ();
    }

    //Gets a movement vector
    public void Move (Vector3 _velocity)
    {
        velocity = _velocity;
    }

    //Gets a movement vector
    public void Rotate(Vector3 _rotation)
    {
        rotation = _rotation;
    }

    //Gets a rotation vector for<span style="font-style: italic; color: #888888;”> camera<br />    public void RotateCamera(Vector3 _cameraRotation)
    {
        cameraRotation = _cameraRotation;
    }

    //Run every physics iteration
    void FixedUpdate ()
    {
        PerformMovement();
        PerformRotation();
    }

    //Perform movement based on velocity<span style="font-style: italic; color: #888888;”> varible<br />    void PerformMovement()
    {
        if (velocity != Vector3.zero)
        {
            rb.MovePosition (rb.position + velocity * Time.fixedDeltaTime);
        }
    }

    //Perform Rotation
    void PerformRotation ()
    {
        rb.MoveRotation(rb.rotation * Quaternion.Euler (rotation));
        if (cam != null) 
        {
            cam.transform.Rotate (cameraRotation);
        }
    }

} 

  • Liked by
Reply