- Home /
2D Platform AI Jump
Hey guys, I'm making a 2.5D AI that moves by using waypoints. I already have this movement towards the waypoints. But what i want now is too make the AI jump onto a higher platform. I have been trying some stuff but every time it doesn't work out as i want it too. My code that moves the Ai at the moment is this :
private void MoveTowardsWayPoint()
{
Vector3 target = wayPointList[currentWayPoint].transform.position;
moveDirection = target - transform.position;
float disY = target.y - transform.position.y;
if (moveDirection.magnitude< 0.2f)
{
GetComponent<CPathFinding>().DFSearch();
currentWayPoint = 1;
}
if (Input.GetKeyDown(KeyCode.A) && controller.isGrounded)
{
print("Jump");
moveDirection.y = 12;
}
moveDirection.y -= 30 * Time.deltaTime;
controller.Move(moveDirection.normalized * 5 * Time.fixedDeltaTime);
}
But now everytime it Jumps it makes a mini jump and it still runs up to the higher platform's. And i already tried to set the moveDirection.x = target.x - transform.position.x ; but that doesn't help either cause then the movement gets fcked up. Anymore a idea how i could do this the best and cleanest.
Thx
Answer by Bip901 · Jun 21, 2017 at 03:07 PM
I didn't understand why your AI needs input (pressing A) to jump... Isn't an ai supposed to do stuff by himself?
Also, try this:
if (target.y > transform.position.y) { //if the target is higher than you
**Jump command here**
}
Your answer
Follow this Question
Related Questions
How to make an AI of a car to jump if there is any obstacle 2 Answers
How do you make a characterController jump automatically when it reaches the edge of a platform? 0 Answers
2D Jump AI Help 0 Answers
Detecting Collision from top side of 2d box collider 0 Answers
2D Plane Component "Gravity" 0 Answers