Hi everyone,
I’m working on a maze-like game, whereby the player has to steer a ball without being detected by guards or cameras! The ball has a kinematic rigidbody and a sphere collider attached to it while the maze itself has a mesh collider attached to it. The problem is that whenever I move the ball towards the wall, the ball simply passes through! Shouldn’t the engine automatically detect that there is a collision and stops the ball from passing through the wall? I tried various collision detection methods (continuous, discrete etc).
Should a script take care of this? Or this can be done natively within Unity? Thanks for your assistance.
There is the simple script attached to the ball gameobject.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class Player : MonoBehaviour {
private float _floatHeight = 0.01f;
private float _floatFrequency = 8f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate(0f, _floatHeightMathf.Sin(_floatFrequencyTime.time), 0f);
if(Input.GetKey(KeyCode.UpArrow))
transform.Translate(Vector3.forward * 0.5f);
if(Input.GetKey(KeyCode.DownArrow))
transform.Translate(Vector3.back * 0.5f);
if(Input.GetKey(KeyCode.LeftArrow))
transform.Translate(Vector3.left * 0.5f);
if(Input.GetKey(KeyCode.RightArrow))
transform.Translate(Vector3.right * 0.5f);
}
}