I'm trying to make the collision work. But...
Hey. Could you look at my script and tell me why it never set "isCol" to false when its not colliding?
using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour {
private float movementSpeed = 20.0f;
private bool isCol;
// Use this for initialization
void Start () {
}
void OnCollisionEnter (Collision col) {
isCol = true;
}
void OnCollisionExit (Collision col) {
isCol = false;
}
// Update is called once per frame
void Update () {
if (isCol == false) {
transform.Translate (Vector3.down * Time.deltaTime);
}
if (Input.GetKey (KeyCode.W)) {
transform.Translate ((Vector3.forward) * movementSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate ((Vector3.back) * movementSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate ((Vector3.left) * movementSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.D)) {
transform.Translate ((Vector3.right) * movementSpeed * Time.deltaTime);
}
Answer by KenConrad · Jan 13, 2016 at 05:00 AM
I would guess you are colliding with something in the scene all the time, like a floor.
You could use a tag or layermask to just have it tell you if you are colliding with what you want to check.
Do both gameobjects have coliders and rigid bodies ? Are the coliders set as triggers ?
Neither of them are set as triggers or rigid bodies .-.
They need to be rigidbodies
http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.OnCollisionEnter.html
It is hard to know what you are try to do, can you describe it in more detail ? pictures ?
i got it. All i had to do was freeze the rotation
Your answer
Follow this Question
Related Questions
Unity3d OnCollisionEnter not firing 1 Answer
Advance Colision Detection 1 Answer
How can i restart a script on collision ? 1 Answer
Check through array list 1 Answer
how do i collide and kill the enemy while pressing space Unity 5 C# 2 Answers