Not sure why my collision is not causing my console to print out "i hit enemy". Player has a rigidbody component, enemy does not.
My enemy has the tag Enemy. Enemy is moving about using transform. My player has the rigid body component, my enemy does not. Any ideas?
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public float maxSpeed = 5f;
private Vector3 input;
private Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if (rb.velocity.magnitude < maxSpeed) {
rb.AddForce(input * moveSpeed);
}
}
void onCollisionEnter(Collision other)
{
if (other.transform.tag == "Enemy")
{
print ("I hit enemy");
}
}
}