Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramming a smooth change of thrust from current velocity vector to a target vector
    text
    copied!<p>TL;dr: "I am not sure how to calculate a smooth transition of thrust between one vector and another."</p> <p>I am programming a simple game where an enemy chases after the player in an open space (no walls). I was calculating the enemy's x &amp; y velocities independently, accelerating them if they were taking them in the direction of the player and quickly slowing them if they were going the wrong way (e.g. EnemyVelocity.x > 0 &amp; player.x &lt; enemy.x, then EnemyVelocity.x - 2.)</p> <p>While the gameplay is decently fun trying to dodge the enemy, it is my desire to have the enemy behave using proper physics. What I am currently doing is have the enemy set their thrust (think a spaceship) based on the angle between them and the player, and have their thrust accelerate up to a max speed (calculating side c of the EnemyVelocity triangle). Once that happens, I'm not sure the best way to have the thrust adjust itself. If I leave no max speed, the enemy accelerates nicely but will easily overshoot the player, and then take a long time to get enough momentum heading back in the player's direction.</p> <p>What I'd like to happen is have the enemy constantly adjust their velocity on the way to the player, targeting wherever they are at (I don't want them to predict where you will be). Then, when they miss the player, I'd like for the same thrust &amp; acceleration formulas to readjust their velocity and send them back at the player.</p> <p>I'm thinking this will involve two vectors: one where the enemy is currently traveling, and one where the enemy wants to travel (the vector that will take them straight to the player). I am not sure how to calculate a smooth transition of thrust between one vector and another.</p> <p>Any tips, formulas or questions will be much appreciated! Thank you Stack Overflow.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload