Question by
Allin1gamer · Mar 05, 2017 at 01:25 PM ·
colliderplayer movementcubetransform.translate
Cube goes through colliders
The cube goes though colliders. I want to limit how far it can move (only right and left controls) i think it ignores colliders due to "transform.Translate(dir * speed);" using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
public float speed = 15f;
public float mapWidth = 5f;
void Start()
{
}
void Update()
{
Vector3 dir = Vector3.zero;
dir.x = -Input.acceleration.y;
if (dir.sqrMagnitude > 1)
dir.Normalize();
dir *= Time.deltaTime;
transform.Translate(dir * speed);
}
void OnCollisionEnter3D()
{
FindObjectOfType<GameManager>().EndGame();
}
}
Comment
Best Answer
Answer by FColor04 · Mar 05, 2017 at 08:38 PM
I think it's beacouse there is no builded in function like OnCollisionEnter3D(), you need to use OnCollisionEnter() instead.
thank you I changed that, it now can get hit by objects but it can still go through the collider blocking me to go outside the map any tips?
I dont know where the error exacly is but i think it may be caused by too high speed, to be safe, you can still use OnCollisionStay() and OnCollisionExit()