I used old Unity 4 and I now I have 5.0.1f1
I have one plane , one player sphere ( cube mesh collision) and some cubes.
Also I have one C# script to make colision under plane and cubes.
I set freeze position and rotation xyz to cubes and freeze position to sphere.
I increase the speed of the player - sphere and
… after some moves the player is out from this …
Somehow the sphere go into cube and leave the plane.
What is wrong with this ?
Thank’s . Regards
using UnityEngine;
using System.Collections;
public class AI_robots : MonoBehaviour {
public float speed = 100.0f;
public float rotationSpeed = 360.0f;
private float pelinOffset;
private float t=0.0f;
// Use this for initialization
void Start () {
pelinOffset = Random.Range (-1000f,1000f);
}
// Update is called once per frame
void Update () {
t += Time.deltaTime;
transform.position -= transform.forward * speed * Time.deltaTime;
transform.Rotate (0.0f, (Mathf.PerlinNoise (t, 0.0f) - 0.5f) * 1.0f * rotationSpeed * Time.deltaTime, 0.0f);
}
void OnCollisionEnter(Collision collision){
transform.forward = Vector3.Reflect (transform.forward,Vector3.ProjectOnPlane(collision.contacts[0].normal,Vector3.up));
GetComponent<Rigidbody>().velocity = Vector3.zero;
GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
}
void OnCollisionExit() {
GetComponent<Rigidbody>().velocity = Vector3.zero;
GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
}
}