Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 588783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:21:18+00:00 2026-05-13T15:21:18+00:00

I’m working on a game where on each update of the game loop, the

  • 0

I’m working on a game where on each update of the game loop, the AI is run. During this update, I have the chance to turn the AI-controlled entity and/or make it accelerate in the direction it is facing. I want it to reach a final location (within reasonable range) and at that location have a specific velocity and direction (again it doesn’t need to be exact) That is, given a current:

  • P0(x, y) = Current position vector
  • V0(x, y) = Current velocity vector (units/second)
  • θ0 = Current direction (radians)
  • τmax = Max turn speed (radians/second)
  • αmax = Max acceleration (units/second^2)
  • |V|max = Absolute max speed (units/second)
  • Pf(x, y) = Target position vector
  • Vf(x, y) = Target velocity vector (units/second)
  • θf = Target rotation (radians)

Select an immediate:

  • τ = A turn speed within [-τmax, τmax]
  • α = An acceleration scalar within [0, αmax] (must accelerate in direction it’s currently facing)

Such that these are minimized:

  • t = Total time to move to the destination
  • |Pt-Pf| = Distance from target position at end
  • |Vt-Vf| = Deviation from target velocity at end
  • |θt-θf| = Deviation from target rotation at end (wrapped to (-π,π))

The parameters can be re-computed during each iteration of the game loop. A picture says 1000 words so for example given the current state as the blue dude, reach approximately the state of the red dude within as short a time as possible (arrows are velocity):

Pic http://public.blu.livefilestore.com/y1p6zWlGWeATDQCM80G6gaDaX43BUik0DbFukbwE9I4rMk8axYpKwVS5-43rbwG9aZQmttJXd68NDAtYpYL6ugQXg/words.gif

Assuming a constant α and τ for Δt (Δt → 0 for an ideal solution) and splitting position/velocity into components, this gives (I think, my math is probably off):

Equations http://public.blu.livefilestore.com/y1p6zWlGWeATDTF9DZsTdHiio4dAKGrvSzg904W9cOeaeLpAE3MJzGZFokcZ-ZY21d0RGQ7VTxHIS88uC8-iDAV7g/equations.gif

(EDIT: that last one should be θ = θ0 + τΔt)

So, how do I select an immediate α and τ (remember these will be recomputed every iteration of the game loop, usually > 100 fps)? The simplest, most naieve way I can think of is:

  1. Select a Δt equal to the average of the last few Δts between updates of the game loop (i.e. very small)
  2. Compute the above 5 equations of the next step for all combinations of (α, τ) = {0, αmax} x {-τmax, 0, τmax} (only 6 combonations and 5 equations for each, so shouldn’t take too long, and since they are run so often, the rather restrictive ranges will be amortized in the end)
  3. Assign weights to position, velocity and rotation. Perhaps these weights could be dynamic (i.e. the further from position the entity is, the more position is weighted).
  4. Greedily choose the one that minimizes these for the location Δt from now.

Its potentially fast & simple, however, there are a few glaring problems with this:

  • Arbitrary selection of weights
  • It’s a greedy algorithm that (by its very nature) can’t backtrack
  • It doesn’t really take into account the problem space
  • If it frequently changes acceleration or turns, the animation could look “jerky”.

Note that while the algorithm can (and probably should) save state between iterations, but Pf, Vf and θf can change every iteration (i.e. if the entity is trying to follow/position itself near another), so the algorithm needs to be able to adapt to changing conditions.

Any ideas? Is there a simple solution for this I’m missing?

Thanks,
Robert

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:21:19+00:00Added an answer on May 13, 2026 at 3:21 pm

    sounds like you want a PD controller. Basically draw a line from the current position to the target. Then take the line direction in radians, that’s your target radians. The current error in radians is current heading – line heading. Call it Eh. (heading error) then you say the current turn rate is going to be KpEh+d/dt EhKd. do this every step with a new line.

    thats for heading

    acceleration is “Accelerate until I’ve reached max speed or I wont be able to stop in time”. you threw up a bunch of integrals so I’m sure you’ll be fine with that calculation.

    I case you’re wondering, yes I’ve solved this problem before, PD controller works. don’t bother with PID, don’t need it in this case. Prototype in matlab. There is one thing I’ve left out, you need to have a trigger, like “i’m getting really close now” so I should start turning to get into the target. I just read your clarification about “only accelerating in the direction we’re heading”. that changes things a bit but not too much. that means to need to approach the target “from behind” meaning that the line target will have to be behind the real target, when you get near the behind target, follow a new line that will guide you to the real target. You’ll also want to follow the lines, rather than just pick a heading and try to stick with it. So don’t update the line each frame, just say the error is equal to the SIGNED DISTANCE FROM THE CURRENT TARGET LINE. The PD will give you a turn rate, acceleration is trivial, so you’re set. you’ll need to tweak Kd and Kp by head, that’s why i said matlab first. (Octave is good too)

    good luck, hope this points you in the right direction 😉

    pun intended.

    EDIT: I just read that…lots of stuff, wrote real quick. this is a line following solution to your problem, just google line following to accompany this answer if you want to take this solution as a basis to solving the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.