- Home /
Question by
Terrified Virus · Feb 19, 2013 at 04:17 AM ·
errormovementrigidbody
Rigidbody makes object "fly" when moving up mountain
Hi guys, in my game, there is a mountain in the middle of the map. The prefab in the game that acts as the enemy spawns on the other side of the map, so it must cross the mountain. The problem is, the rigidbody that the prefab has makes it shoot of the mountain when crossing it. I don't know what is happening, but sometimes the object will shoot up and not come down for 2 more minutes. Here is the code I am using:
var targetg : GameObject;
targetg = GameObject.Find("First Person Controller");
var target : Transform;
target = targetg.GetComponent(Transform);
var speed : float;
var yval : float;
static var seen : float;
seen = 0;
var object1 : GameObject;
var object2 : GameObject;
var distance;
object1 = GameObject.Find("First Person Controller");
function OnBecameInvisible()
{
speed = 20f;
seen = 0;
}
function OnBecameVisible()
{
speed = 0f;
seen = 1;
}
function Update(){
yval = transform.position.y;
object2 = PlayerControl.enemyObject;
if(!renderer.isVisible){
transform.position = Vector3.MoveTowards(transform.position, Vector3(target.position.x,yval,target.position.z), speed*Time.deltaTime);
transform.LookAt(Vector3(target.position.x,yval,target.position.z));
transform.rotation *= Quaternion.Euler(0f, 180f, 0f);
distance = Vector3.Distance(object1.transform.position,object2.transform.position);
if(distance<4){
PlayerControl.dead = 1;
}
}
}
Comment