Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help with multiplayer!

Hey, i can't figure out why w, a, s, d isin't working :(

PlayerController:

using UnityEngine;


[RequireComponent(typeof(PlayerMotor))]

public class PlayerController : MonoBehaviour {


  [SerializeField]

  public float speed = 5f;

  [SerializeField]

  private float lookSensitivity = 3f;


  private PlayerMotor motor;


  void Start ()

  {

    motor = GetComponent<PlayerMotor>();

  }



  void Update ()

  {

    //Calculate movement velocity as 3D vector

    float _xMov = Input.GetAxisRaw("Horizontal");

    float _zMov = Input.GetAxisRaw("Vertical");


    Vector3 _movHorizontal = transform.right * _xMov;

    Vector3 _movVertical = transform.forward * _zMov;


    // Final Movment vector

    Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;


    //Apply movment

    motor.Move(_velocity);


    //Calculate rotation as a 3d vetor (turning around)

    float _yRot = Input.GetAxisRaw("Mouse X");


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


    //Apply rotation (mouse)

    motor.Rotate(_rotation);


  }

}


PlayerMotor:

using System;

using UnityEngine;


[RequireComponent(typeof(Rigidbody))]

public class PlayerMotor : MonoBehaviour

{



  private Vector3 velocity = Vector3.zero;


  private Rigidbody rb;

  private Vector3 rotation = Vector3.zero;


  void Start()

  {

    rb = GetComponent<Rigidbody>();

  }


  //Gets a rotational vector

  public void Rotate(Vector3 _rotation)

  {

    rotation = _rotation;

  }


  //Run every phisics iteration

  private void FixedUpdate()

  {

    PerformRotation();

  }


  //Preform movment based on velocity variable

  void PerformMovment ()

  {

    if (velocity != Vector3.zero)

    {

      rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);

    }



  }


  //Preform rotation

  void PerformRotation ()

  {

    rb.MoveRotation(rb.rotation * Quaternion.Euler (rotation));

  }


  public void Move(Vector3 velocity)

  {

     

  }

}

Answers

  • HNJHNJ Member

    please use code block, it is not able to understand.

Sign In or Register to comment.