- Home /
Why Does My Prefab Fly Upwards When Moving Around?
So I'm making an overly-simple FPS, and below is the zombie movement script. They're simplistic bodies using joints and limbs to almost resemble a human. However, upon spawning, my zombies constantly fly straight upwards, reach a max height, fall down to the terrain and bounce back up. I know it's a problem with the GroundToTerrain() below, but I can't seem to figure out what it is.
Does anybody have a good idea?
var speed : float = 3.0f;
var bodyHeight : float = 4.0f;
function Start () {
GroundToTerrain();
rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
}
function Update () {
GroundToTerrain();
rigidbody.velocity = Vector3.forward * speed;
}
function GroundToTerrain(){
var hit : RaycastHit;
Physics.Raycast(transform.position, -transform.up, hit );
transform.position.y = hit.point.y + bodyHeight;
}
Your answer
Follow this Question
Related Questions
Rigidbodies violently repel when replacing with pre-shattered opject 2 Answers
Removing A Component From An Instantiated Prefab After X More Are Instantiated 1 Answer
changing the speed of an enemy on key press? 2 Answers
Ping Pong bat is not detecting the collision with the wall 1 Answer
is it possible to effect physics object with non physics character? 1 Answer