Simple Boat Physics

Blitz3D Forums/Blitz3D Beginners Area/Simple Boat Physics

Jeeps(Posted 2007) [#1]
Hi to all.

I just want to make some simple physics for my seabattle game. I want my ship to accelerate to it's top speed. Decel off throttle,decel when changing direction and decel as ship rotates at cruise. Varibles are topspeed, accel, turnspeed, x,y,xv,yv. I have 36 ship frames, 1 per every 10 degrees of rotation. This game is in 2d mode. Arrow keyup to acel, arrowleft and right to rotate.

Please give me some pointers to this up.

Thanks


octothorpe(Posted 2007) [#2]
This might get you started...


Drag (.98) keeps the ship from accelerating indefinitely (just like with Newtonian physics.) We apply a higher drag (.96) when the ship is turning to cause it to decelerate more.

Deciding which image to use is as easy as correcting the ship direction to 0-360, then dividing by 10 degrees per frame to get your frame index.

You'll probably want to tweak the functionality of the down arrow depending on current speed: it's a lot easier to brake than to drive in reverse! This may also apply to the up arrow if the player is going backwards. Also, you may want to lower the reverse deceleration: it's typically easier to go forwards than backwards, but this may depend on the type of ship.

You may also want to apply turning acceleration: in BF1942, when you turn a ship it takes a while to start turning, and continues turning after you let go. Nice touch for simulations, maybe not so nice for arcade games. Cobra Triangle would have been clumsy with that feature.


Stevie G(Posted 2007) [#3]
For a better fit on the displayed image you should use ..

ShipImageNo = ( ( Angle + 5 ) mod 360 ) / 10

Reason being, for example, you have images 0-35 so between 355 and 4 degrees you'll want to display image 0 rather than image 35 between 350 and 359 degrees and image 1 between 0 and 10.

Hope that made sense?
Stevie


Jeeps(Posted 2007) [#4]
Thanks! Octothorpe

The code snippet works good with the png image. I just had to change the plus sign to minus on the line that updates the x coordinates.

s\x = s\x - Sin(s\dir) * s\speed
s\y = s\y + Cos(s\dir) * s\speed

I will play around with the numbers to get the topspeed I need for different ships and acceleration.

Thanks! Stevie G

ShipImageNo = int( ( Angle + 5 ) mod 360 ) / 10

I added this to my code converting it to integer. The boat seams to point straight down when moving down.