- Home /
Question by
samizak · Mar 14, 2015 at 02:33 PM ·
javascriptaitag
unity3d: making the AI jump over obstacle with a tag
hi,
I have a simple AI which just goes forward. In front of the AI there is an obstacle (just a cube) with a tag "terrain". What i want my AI to do is jump over it. Here is what i have:
#pragma strict
var Speed : float = 2;
var jumpSpeed : float = 8.0;
var vSpeed : float = 0.0;
function Awake () {
myTransform = transform;
}
function Update () {
if(jump == true){
vSpeed = jumpSpeed;
}
if(jump == false){
vSpeed = 0;
}
// not a very smooth jump but probably good enough
myTransform.position += myTransform.up * vSpeed * Time.deltaTime;
// move forward
myTransform.position += myTransform.forward * Time.deltaTime * Speed;
}
function OnCollisionEnter(col : Collision){
if(col.gameObject.tag == "terrain"){
jump = true;
}
}
// i don't think this part is working
function OnCollisionExit (col : Collision) {
if(!col.gameObject.tag == "terrain"){
jump = false;
}
}
My AI does jump over the obstacle but then keeps jumping and i cant find a way to stop it from jumping
plz help
And thx in advance
Comment
Answer by tanoshimi · Mar 14, 2015 at 06:42 PM
Why did you negate the tag in OnCollisionExit? It seems like it should be:
function OnCollisionExit (col : Collision) {
if(col.gameObject.tag == "terrain"){
jump = false;
}
}
Your answer
Follow this Question
Related Questions
i can't set destination, using AI Navmesh via raycast 1 Answer
Player Health drops fast, how to pause after damage 0 Answers
Basic Enemy Javascript 0 Answers
AI walk through solid walls 1 Answer