На них есть BoxCollider и Rigidbody и на игроке то же это есть. Вот скрипт. Помогите пожалуйста!
spoiler
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class Controller : MonoBehaviour {
private Rigidbody rb;
[SerializeField]
private float speed = 5.0f;
[SerializeField]
private float lookSpeed = 3.0f;
private Vector3 velocity = Vector3.zero;
private Vector3 rotation = Vector3.zero;
void Start() {
rb = this.GetComponent();
}
public void Move (Vector3 _velocity){
velocity = _velocity;
}
public void Rotate (Vector3 _rotation){
rotation = _rotation;
}
void FixedUpdate () {
PerformMove ();
PerformRotation ();
}
void PerformMove () {
if (velocity != Vector3.zero)
rb.MovePosition (rb.position + velocity * Time.fixedDeltaTime);
}
void PerformRotation () {
rb.MoveRotation (rb.rotation * Quaternion.Euler (rotation));
}
void Update() {
float xMov = Input.GetAxis ("Horizontal");
float zMov = Input.GetAxis ("Vertical");
Vector3 movHor = Vector3.right * xMov;
Vector3 movVer = Vector3.forward * zMov;
Vector3 velocity = (movHor + movVer).normalized * speed;
Move (velocity);
float yRot = Input.GetAxis ("Mouse X");
Vector3 rotation = new Vector3 (0f, yRot, 0f) * lookSpeed;
Rotate (rotation);
}
}