- Home /
AI is over floor When player jump
THis is my AI that i use
When player jump AI is over floor how to set them not over floor
IN JAVA SCRIPT AI2.JS
var player: Transform;
private var distance: float;
private var currentwaypoint : int;
var waypoint : Transform[];
var target : Transform;
function Start() { player=GameObject.FindGameObjectWithTag("Player").transform; }
function Update () {
distance=Vector3.Distance(transform.position,player.position); }
if (distance <=1.5f) {
}
else { transform.rotation= Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(player.position-transform.position),Time.deltaTime*4); transform.Translate(0,0,.05f);
}
}
Thank you for ALL answer
Answer by Stradagee1 · Nov 14, 2011 at 10:50 PM
I ran into a similar problem when creating the AI script my game. After trying your code in my own scene, I changed the inside of your else block to look like this:
var direction = target.position - transform.position;
direction.y = 0;
if (direction.magnitude < 0.5) {
return;
}
// Rotate towards the target
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(direction), 4 * Time.deltaTime);
transform.eulerAngles = Vector3(0, transform.eulerAngles.y, 0);
// Modify speed so we slow down when we are not facing the target
var forward = transform.TransformDirection(Vector3.forward);
// Move the character
direction = forward * 10;
GetComponent (CharacterController).SimpleMove(direction);
For the above to work, you'll need to add a Character Controller to your AI. The reason it works as opposed to what you did, I think, is because SimpleMove takes into account whether or not the transform is on the ground, so it can simulate gravity.
Your answer
Follow this Question
Related Questions
simple AI - Beginner question 2 Answers
Enemy AI monster problem 3 Answers
Trouble with turret script 1 Answer
What is AutoWayPoint 1 Answer
[C#] Raycast based AI 2 Answers