开发者

AI, moving towards target by apply force

开发者 https://www.devze.com 2023-04-12 18:45 出处:网络
I have a level containing points in 2D, one being controlled by the user the rest being controlled by the required AI, the points move by applying a set amount of force each second which is pushed int

I have a level containing points in 2D, one being controlled by the user the rest being controlled by the required AI, the points move by applying a set amount of force each second which is pushed into the velocity divided by their mass, which is then pushed into the position each second, the velocity is maintained between calculations (momentum). What I'm looking for is a way to apply force so I can move towards a particular target and collide.

I've tried multiplying the normalized vector pointing towards the target by the set force, It works if the velocity of both is zero when starting, unfortunately points will need to attack multiple targets one after the other, what ends up happening is the predator will circle around the target getting closer with each rotation. Thanks.

tl;dr I need to the AI to mo开发者_运维技巧ve towards the targets by applying force in 2D. Thanks.


Let v' be the velocity vector that you want to assume with your seeker. Most simple, if the target were to move without accelleration and your seeker would go on with v' they would meet. (*)

Now don't just add some momentum in the form of v'! Let v be the current velocity of your seeker. You need to apply a force in the direction of v' - v to change your seeker velocity towards v'.

*) Ok, it's not that simple. There are infinitely many meeting points (unless the target is still). Deciding on a meeting point can be done by choosing the earliest point that can be reached with a given amount of momentum applied to the seeker.

Just a remark

Maybe your game (?) gets more realistic if you apply a fixed amount of energy instead of a fixed amount of momentum each round. But this is just a guess.

About mass

To make it realistic you should probably let the mass be proportional to either the square of the radius (assuming a 2D world with circles) or to the cubic of the radius (assuming a 3D world and a sphere).

Momentum vs. energy

Momentum is v m while energy is 1/2 v^2 m. When applying a fixed amount of energy it becomes harder to further accelerate fast objects.

In reality to maintain a fixed acceleration [m/s per s] you will need an ever encreasing amount of enery per time vs. you need a constant amount of momentum per time to do the same.

Caveat

If you make it follow the laws of physics more closely this does not necessarily make it look more realistic. My opinion is that you should try both ways and decide for what "feels" best. Or just leave it as it is if you're feeling happy with it.


Remember to move toward the target's position at time now + t. t is the collision time. You have to combine the seeker and target's motion equations and solve for t and the vector.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号