So, we’re writing a basic snake game and having the issue where when we collide with the box it makes us start slowly rotating, sadly the OnCollisionEnter won’t work unless there is a physical collision. Here is the script so you can help me out.
I need to find a way to make it so it doesn’t move me when I collide with it, like… Make a stationary collision as terrain does. When you hit it, it doesn’t make you “Bounce”
I need to remove the “Bounce” in the collision.
It’s a sphere and a cube, sphere has sphere collider and rigidbody, cube has cube collider and rigidbody, without these the script doesn’t do anything when I touch the object.
Movement.cs
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour
{
public float speed;
public float rotateSpeed;
public Transform myTransform;
void Start ()
{
speed = 5.0f;
rotateSpeed = 5.0f;
myTransform = transform;
}
void Update ()
{
if(Input.GetKey(KeyCode.W))
myTransform.position += myTransform.forward * speed * Time.deltaTime;
if(Input.GetKeyUp(KeyCode.A))
{
transform.Rotate(0,-90,0);
}
if(Input.GetKeyUp(KeyCode.D))
{
transform.Rotate(0,90,0);
}
}
}
Collision.cs
using UnityEngine;
using System.Collections;
public class CollisionHandler : MonoBehaviour {
HealthHandler healthHandler;
void Start() {
healthHandler = GetComponent<HealthHandler>();
}
void OnCollisionEnter(Collision collision) {
if(collision.gameObject.tag == "Enemy") {
Destroy (collision.gameObject);
healthHandler.currentHealth -= 10;
Debug.Log ("Hit Enemy");
}
}
}