Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Proper propulsion method for a boat in the water ...

Author
Message
ProfVersaggi
12
Years of Service
User Offline
Joined: 6th Apr 2012
Location: Maastricht Netherlands / Chicago, USA
Posted: 25th Nov 2012 23:36
I'm experimenting with propulsion methods for a boat in the water and could use a pointer or two...

Currently the boat is a physics enables sprite and I'm attempting to use the SetSpritePhysicsForce command to give it propulsion, but it's failing miserably because of the way the vectors are behaving. It really seems like the wrong choice for the job. I'm using SetSpriteAngle to turn the boat, but I'd like to use something functional for the propulsion force.

Is there anything out there that comes to time that could provide force behind a single point regardless of where that point is located (like a propeller).

Many thanks in advance...

----
From the Desk of Prof Versaggi ...
Auger
12
Years of Service
User Offline
Joined: 21st Aug 2011
Location: Out There
Posted: 26th Nov 2012 03:44
You could have a look at
SetSpritePhysicsImpulse( iSpriteIndex, x, y, vx, vy )

It works like Physics force but it's only applied once unlike physics force which is applied constantly.


Auger
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Nov 2012 10:11
Take a look at the code I provided here:
http://forum.thegamecreators.com/?m=forum_view&t=201704&b=41

It should work in a very similar way to what you are looking for using SetSpritePhysicsImpulse as Auger suggested. Just change what affects the angle of the sprite and it should be pretty close. You could even play with the sparks to make them look like water spray with a little effort...


this.mess = abs(sin(times#))
ProfVersaggi
12
Years of Service
User Offline
Joined: 6th Apr 2012
Location: Maastricht Netherlands / Chicago, USA
Posted: 26th Nov 2012 12:03
Thanks Auger, that did the trick. The other technique I used which make the whole thing workable was to record the angle that the boat was heading toward and construct a series of if/then's to invoke a series of proper (Vx, Vy) settings that effectively gave me up, down, left, right, and up-right, up-left, down-right, down-left propulsion directions.

Here's the code snippet:




----
From the Desk of Prof Versaggi ...
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 26th Nov 2012 17:27
Optimisation point:

You could make this a lot faster by using if-else constructs in your big list of "if" statements because the entire set of tests is done even if the first case is true.

Just a thought! I always worry about a lot of ifs

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
ProfVersaggi
12
Years of Service
User Offline
Joined: 6th Apr 2012
Location: Maastricht Netherlands / Chicago, USA
Posted: 26th Nov 2012 21:15
Thanks Jim, good point, I made that change immediately ...

----
From the Desk of Prof Versaggi ...
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 27th Nov 2012 01:18
It's always worth thinking about the most probable order. In this case, I can't see any ranking, because the angle could be any one of eight. Unless the last angle was a predictor of the next angle. Scary!

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 27th Nov 2012 19:02 Edited at: 27th Nov 2012 19:05
I was pretty sure there was a better solution so I wrote this:



This will add the force at a given distance and a given angle local to the sprite.

Login to post a reply

Server time is: 2024-05-03 15:16:33
Your offset time is: 2024-05-03 15:16:33