The Daily Click ::. Forums ::. Klik Coding Help ::. Steering Problem
 

Post Reply  Post Oekaki 
 

Posted By Message

-J-



Registered
  05/10/2008
Points
  228

VIP MemberThe Cake is a Lie
12th April, 2009 at 12:15:30 -

I have this habit of always trying to find the simplest way of making something work.. it usually means it takes me ages to code a game because I'm never happy with it

As for finding out Acceleration and Turning... Sorry but I have no idea , this one has finally stumped me .


 
n/a ...

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th April, 2009 at 12:41:37 -

No problem - I really appreciate all your help up to this point
You want some more DC Points? I have lots and there's nothing to spend them on anyway


This is what someone else has told me:

"I'm pretty sure (in Critical Mass) acceleration works instantaneously at the start of each turn and you will move each turn with a constant speed.

I can see that in the quadratic example there, P1 is most definitely not end point if turn/accel=0. it is basically the intersection between the line you would travel if turn=0 and the line you would be traveling in after the turn (extending backwards).
now, i am assuming you will want to approximate a circular arc as this is what it's like in CM as far as I can see. after some geometry/trig, the point P1 is a distance d=(r/2)/cos(θ along the line of travel if turn=0, where θ = angle between line of travel if turn=0 and line between ship and mouse and r is distance from ship to mouse."

 
n/a

-J-



Registered
  05/10/2008
Points
  228

VIP MemberThe Cake is a Lie
12th April, 2009 at 13:47:47 -

Glad I could help

Good luck and Happy Easter!



 
n/a ...

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
15th April, 2009 at 21:23:25 -

Well, I eventually managed to get something working that I'm happy with. Thanks to Julian, and everyone else who helped.
I'll still change a few things, such as making the arrow a solid line instead of dotted, but the hard part is done now.

Anyway, the big change, which made it possible, was getting rid of the gradual acceleration. Instead, the ship now accelerates instantly to its new speed at the start of the turn. This means that the movement curve is now simply a circular arc, which makes the maths *much* simpler.
As it turns out, this is the same method as used in "Critical Mass" (the game I'm kind of copying), so it's ok


Here's an example file:
http://cid-b1e7ee094271bbda.skydrive.live.com/self.aspx/Public/CMMove.mfa


Here's a brief summary of the maths used:

Image

* Find A1;
Difference between initial heading and angle from start to finish points.

* Find A2;
90 - A1
We know P3 is at a 90 degree angle from the original heading.

* Find A4;
180 - (A2 * 2)
A2 and A3 are the same, and interior angles of a triangle always add up to 180.
This is also the angle the ship turns through.

* Find distance from P3 to P4;
We know A2 and A3, and can calculate the distance from P1 to P2 (using Pythagoras' theorum), so we can use "triangulation".

* Find distance from P3 to P1;
We know the distances from P3 to P4 and from P1 to P4 (half the distance from P1 to P2), so we can use Pythagoras' theorum.
This is the radius of the circle who's arc is travelled along.

* Find length of arc travelled;
We know the radius of the circle, so by dividing by 360, and multiplying by the total angle travelled (A4), we can find the distance travelled.
This gives us the new speed of the ship. By subtracting the initial speed we can find the acceleration.

* Find acceleration & turning;
We know the total change in angle and speed, so can divide these by the number of frames, to find the change per frame.


Actually, it's a bit long-winded. I could have use the law-of-sines and skipped a couple steps, but whatever.

Edited by Sketchy

 
n/a
   

Post Reply



 



Advertisement

Worth A Click