Hi,
So earlier I posted this on how to get AI to jump in an arc. But I realised it was probably in the wrong place on this forum.
However, I'm not even convinced I'm going about solving this the right way. So I would like to know what techniques I can use to get an AI to jump between to platforms in a 2d game?
Currently, I'm using SUVAT physics equations to calculate the arc path between nodes but I'm having difficulties getting my ai to follow the jump path. I can get my ai to follow the jump path using the starting position and using initail velocity I can displace the the ai's position. But this sets the ai's position directly and basically ignores any physics. Ofcourse, I can add some extra code to detect a collision in mid air and stop and apply gravity if there is a collision. But I already have collision detection code but the interface requires setting a the velocity on the object. So my current thought is between:
- Set ai's position using suvat equation such as: s = ut + (1/2)(a)(t^2). Where I can get the initail velocity and time to target and then simply follow the path and then implement some code to detect collisions while jumping. The path following is really quite smooth.
- Some how set the velocity of the ai using: v = u + at which ends up with weird movement but allow to reuse some existing code I have. not sure my implementation is even correct here.
- Use some other better method that I am not aware of.
Does any one have any thoughts on this? The code below is what I'm doing while for point 2:
IEnumerator Jump(LaunchData launchData) {
float timer = 0.0f;
while (timer <= launchData.timeToTarget) {
velocity.x = launchData.initialVelocity.x + (timer);
velocity.y = launchData.initialVelocity.y + (timer * gravity);
timer += Time.deltaTime;
enemyController.Move(velocity * Time.deltaTime);
yield return null;
}
jumping = false;
}