AI/Movement

Member
Posts: 94
Joined: 2008.08
Post: #1
Hi There,

I've developed this game: spacerage.co.uk and Im attempting to get the movement of the ships better.

At the moment, they work by the ships having a real target and a fake target (both 3d vectors). The ships always point towards the fake target, using this method. The fake targets are always chasing the real targets. The problem with this is, that the fake targets have to move slow enough so that the ships turn smoothly, but that means the ships catch the fake target up, causing the quaternionFacingPoint function to break because its trying to point the ship at a point which is too close to where it currently is. [I hope this makes sense] But this often causes the ships to suddenly 'flip' and not always have a smooth motion.

I've also tried sending out points in each direction around the ship to see which of these points is closest to its target, and then turning in that direction. But this has very unpredicatable results, and the ship tends to 'shake' and then often just spirals off.

One method Im thinking of is to again have the fake target and always have the ship pointing at it again. But instead of the fake target being a 3d vector as a position in space, it should sort of 'sit' on a sphere around the outside of the ship, and move gradually to point towards the real target. The problem is, Im not sure of how to work out the maths for this method. Any clues?

Anyway, does someone have a better idea of how to do this?

Many thanks! Smile
Quote this message in a reply
Member
Posts: 59
Joined: 2007.12
Post: #2
You could stop updating the rotation when the target is really close, and just keep whatever orientation the ship had before.

"it should sort of 'sit' on a sphere around the outside of the ship, and move gradually to point towards the real target. The problem is, Im not sure of how to work out the maths for this method. Any clues?"
This sounds very much like quaternions to me.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
You're likely to get better results if you apply rotation forces gradually, with some rotational acceleration, deceleration, and maximum speed constants, rather than setting the ships' orientations directly. I'd probably do something like take the cross product of ship's current front vector and vector to its target, clamp your angle to some maximum value, then rotate based on that.
Quote this message in a reply
Member
Posts: 94
Joined: 2008.08
Post: #4
ThemsAllTook Wrote:You're likely to get better results if you apply rotation forces gradually, with some rotational acceleration, deceleration, and maximum speed constants, rather than setting the ships' orientations directly. I'd probably do something like take the cross product of ship's current front vector and vector to its target, clamp your angle to some maximum value, then rotate based on that.

I agree, Im wondering how to work out which axis to rotate the ship on though, based on the resulting angle from the cross product?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #5
Cross product gives you the axis. Dot product gives you the angle.
Quote this message in a reply
Member
Posts: 94
Joined: 2008.08
Post: #6
Ah of course Smile I'll give that a try tonight, and let you know how it goes, thanks! Smile
Quote this message in a reply
Member
Posts: 94
Joined: 2008.08
Post: #7
Hey, I just got around to trying that, and it works perfectly thanks!! Smile

I was slipping up first as I needed to workout the vector to the target from the ship, rather than just using the targets coords. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  glutWarpPointer lag and fps movement Ropeburn 3 6,739 Jan 18, 2011 09:47 PM
Last Post: OneSadCookie
  Slower Movement Nick 7 3,833 Aug 27, 2004 02:15 PM
Last Post: Josh