Jump to content
  • Advertisement
sun113344

Techniques to get AI to jump between nodes in a path

Recommended Posts

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:

  1. 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.
  2. 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.
  3. 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;
}

 

Share this post


Link to post
Share on other sites
Advertisement

Do you want it to jump with actual physics (with the possibility of missing/failing in various events) or you just trying to fake a fixed path to look nice? Normally for jumping I essentially just add some "upwards" velocity then let the physics determine when it lands (or hits it head, flies into a wall, etc.). Largely the same logic for falling off a ledge, etc., but possibly play a different animation.

 

Not done it in Unity specifically, but for AI/NPC I have used the same jump physics as my player character, and for AI purposes either code it into the map that jumping from A to B is possible, or if I wanted a more dynamic AI, I think Id look at estimating the jump, but even then use the normal physics to actually do so.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!