'Brackeys Player Motor script doesn't work
The Problem
I'm following the Brackeys multiplayer tutorial and I got stuck in episode 2. I wrote the script just like in the video, no errors but I still cant look around. This script is put onto a 3D blender-made model. this is the code V
The Code
private Vector3 velocity = Vector3.zero;
private Vector3 rotation = Vector3.zero;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// gets a movement vector
public void Move(Vector3 _velocity)
{
velocity = _velocity;
}
// gets a rotational vector
public void Rotate(Vector3 _rotation)
{
rotation = _rotation;
}
//run every physics iteration
void FixedUpdate()
{
PerformMovement();
PerformRotation();
}
//perform movement based on velocity variable
void PerformMovement()
{
if(velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
}
//Perform rotation
void PerformRotation()
{
rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
