- Home /
Question by
valtteri_m · Dec 19, 2014 at 08:22 PM ·
2djavascriptaijumploop
2D Jump AI Help
I have a 2D mob ai jump script that if the player is higher than the mob, the mob will jump. But I have a problem where it wont stop jumping so it just flies away to space.
private var Player : Transform;
var JumpPower = 150;
var JumpTrigger = 1;
function Start(){
Player = GameObject.FindWithTag("Player").transform;
}
function Update(){
//Jump AI
if(Vector2.Distance(transform.position, Player.position) > JumpTrigger){
Jump();
}else{
//rip
}
}
function Jump(){
rigidbody2D.AddForce (Vector2.up * JumpPower);
yield WaitForSeconds(2.0);
}
Comment
Put a timer delay in your script, or let the mob only jump again if it collide with the ground again. (touch the ground)
Oh yeah the check for ground thing, thats important thanks
Your answer
Follow this Question
Related Questions
AI isn't looping (Javascript) 1 Answer
Problem with jumping 1 Answer
Detecting Collision from top side of 2d box collider 0 Answers
How to correctly shorten this script using arrays and iterations 2 Answers
Collsions problem 0 Answers