Simple steering behaviour vector help

Hi guys,

If i was to have a 2d pitch and wanted to move a player(circle) towards a target on the pitch, how would you program this behaviour?

desired_velocity = normalize (position - target) * max_speed
steering = desired_velocity - velocity

I have vectors for both position and velocity. Basically an object that holds a float for both x and y. How would I then go about writing this? ???

Any help greatly appreciated,

Thanks

HI!
Sorry but I can’t figure out your request. What do you mean with steering ? Is that a sort of Pathfinding ?

Is this what you need: http://workshop.evolutionzone.com/old/2003spring/vector_maths.html?

Looks like you’re pretty close to the answer already! You should use “normalize(target - position)” though (rather than “position - target”) so that the player moves towards the target, not away from it.

The player then accelerates in the direction of your “steering” vector. For this you’d write something like

velocity = velocity + acceleration * normalize(steering)

where “acceleration” is the amount by which the player’s velocity can change in one turn.

Be warned that this approach may have some odd side-effects! In particular, the player may go into orbit around the target! With a bit of experimentation (and, possibly, some friction) you should be able to make it do what you want though.

I hope that’s some help. Apologies if I misunderstood your question.

Simon

Yes! Thank you!!

I stumbled on through and managed to knock up all of the vector maths for my classes and got the seek behaviour to work. I was so confused as to why it wasn’t working as I thought it should. Read your post and realised I was taking away the wrong one lol. Position - target was the problem.

Thanks so much, you just made me a very happy steering behaviour enthusiast 8)

P.s thanks again :slight_smile: