Game Development Reference
In-Depth Information
So, let's replace some old code in the Jump() funcion so that it looks similar to the
following code:
//Make character Jump
public function Jump (_direction : Vector3) : boolean {
//Checking for Jumping if the next y position is different than the
current y position
var hit : RaycastHit;
//Optimization
var v3_leg : Vector3 = transform.position + controller.center +
Vector3.up * (-controller.height*0.5);
var f_distance : float = controller.radius * 2;
if ((Physics.Raycast(v3_leg, _direction, hit, f_distance)) &&
(c_collisionFlags & CollisionFlags.Sides)) {
if (hit.transform.tag == "Wall") {
return true;
}
}
return false;
}
From the preceding code, we basically change the checking from the capsule cast to the
ray cast by drawing the line from the botom of our AI in the given direcion, which is much
faster because we only draw one line and not a whole capsule.
Now, we click Play and check our FPS to see whether the problem has been fixed by checking
the Statistics window while the AI is moving and is staionary.
 
Search WWH ::




Custom Search