- Home /
Simple AI and jump
I have a little cube that I can tell where I want it to move. I click somewhere, pass that position to the cube, and have the cube move. But I want it to jump over other cubes or obstacles if there is one in the way. Here's what I have...
void move(Vector3 pos){
Vector3 nV = pos;
nV.y = transform.position.y;
//this ignores the y component so it isnt pushing into the ground
if(Physics.Raycast (transform.position,nV,15f)){
if(isGrounded == true){rigidbody.velocity = Vector3.up * 15;}
} else{
if(transform.position.x != nV.x && transform.position.z != nV.z){
transform.position = Vector3.MoveTowards (transform.position,nV,.3f);
}else{HasTask = false;}
}
}
At the moment, this script works 1/2 the time. And when it does, it first collides straight into another cube, jumps, then continues. I want this to be a fluid movement, not all choppy and such. If there is any way that you can help, please do. Thanks in advance!
Look at Time.deltaTime to smooth things out a bit.
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.$$anonymous$$oveTowards.html
I have pretty much that. Its not the "moving towards" the point thats the issue, its the jumping.
Well, at last in what you posted, you don't have that at all (re: time.deltaTime). Could you clarify what about the jumping is the issue?
yes, that is what I am asking about. It moves towardws the object fine, however, when it gets in front of an obstacle, it will either plow right through it, jump, jump to early, or just stop moving altogether. is really a 50/50 thing when it works...
from my understanding you can't have 2 else{}. Try changing the first one to else if{}. Also nV = pos is confusing me. If I knew what that meant I get the feeling I could figure this out.
Your answer
Follow this Question
Related Questions
Dynamic jump? 1 Answer
Sound help with script 1 Answer
Creating A wall Jump 0 Answers
Simple jump code? 2 Answers
Nested Prefab Issue 0 Answers