Multiplayer FPS Tutorial Issue

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

I’ve just started following Brackeys’ multiplayer FPS tutorial.  I am still only on the movement portion and I have written my scripts just like he did. However, I am having an error that didn’t show up for him.  When I used the != and + operators to compare or add Vector3s, an error pops up saying “Operator ‘+’ is ambiguous on operands of type ‘Vector3’ and ‘Vector2′” and the same thing for the operator !=. I am confused and I don’t know how to fix my scripts. Please help!

(Edit) Here are my scripts:

PlayerMotor

using UnityEngine;

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

private Vector2 velocity = Vector3.zero;

private Rigidbody rb;

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

public void Move(Vector3 _velocity)
{
velocity = _velocity;
}

void FixedUpdate()
{
PerformMovement();
}

void PerformMovement()
{
if (velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
}

}

PlayerController

using UnityEngine;

[RequireComponent (typeof (PlayerMotor))]

public class PlayerController : MonoBehaviour {

[SerializeField]
private float speed = 10f;

private PlayerMotor motor;

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

void Update()
{
float xMov = Input.GetAxisRaw(“Horixontal”);
float zMov = Input.GetAxisRaw(“Vertical”);

Vector3 MovHor = transform.right * xMov;
Vector3 MovVert = transform.forward * zMov;

Vector3 velosity = (MovHor + MovVert).normalized * speed;

motor.Move(velosity);

}

}

 

(Edit)

HOLY SHIT, I am such a dumbass. It’s because I wrote velocity as a Vector2 in the first script, oh my god.

  • Liked by
Reply