- Home /
My Y position goes fixed to some value
I have made battle arena in which I have put Box Collider( no trigger included ), Mesh Collider( triger included, convex included), Terrain Collider(triger included) and two object vehicles( Rigidbody and Mesh Collider ) and along it I have made wander script. Now what I want here is for objects to move along the terrain, however every time I try, it either falls off the terrain or go at some y rate which is +2 in units higher that it is supposed to be( it is 3 valued, and it goes up to 5.000019 without any reason ). So, I am pleading you to discuss this matter, in order to solve the possible cause of it. As far as I know, the scripts behavior is out of question for this issue.
#pragma strict
var Speed= 2;
var wayPoint : Vector3;
function Start(){
//initialise the target way point
Wander();
}
function Update()
{
// this is called every frame
// do move code here
transform.position += transform.TransformDirection(Vector3.forward)*Speed*Time.deltaTime;
if((transform.position - wayPoint).magnitude < 3)
{
// when the distance between us and the target is less than 3
// create a new way point target
Wander();
// don't need this
//transform.LookAt(wayPoint);
//transform.position += transform.TransformDirection(Vector3.forward)*Speed*Time.deltaTime;
}
}
function Wander()
{
// does nothing except pick a new destination to go to
wayPoint= Vector3(Random.Range(0, 300),3, Random.Range(0, 300));
// don't need to change direction every frame seeing as you walk in a straight line only
transform.LookAt(wayPoint);
Debug.Log(wayPoint + " and " + (transform.position - wayPoint).magnitude + gameObject.name);
}
Comment