'Thrust' Physics

Forum Home Forum Home > Construct Classic > Construct Classic Discussion > Help & Support using Construct Classic
 Post Reply Post Reply Page  123>
Author
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Topic: 'Thrust' Physics
    Posted: 20 Jun 2010 at 4:27pm
Hey everyone. I've been looking everywhere for tutorials and they seem rare, even for code, never mind construct!

I'm looking to prototype a simple space shooter type movement, something like Asteroids, Thrust etc. I've gotten a basic setup done with custom movement, and I think I understand how that particular object works... but I'm trying to implement the correct physics, using events and avoiding using many of the built in behaviours. This is only because I prefer to know what's going on and don't like the idea of something changing in another version and breaking everything :P

So I suppose what I'm stuck on is how to implement the movement of a single sprite... I want to use vectors maths but I'm unsure what the correct way to implement them would be. I assume you should set up separate private variables like XPostion, YPosition, Angle... is there any advantage to making a few vector functions (dot product, cross product etc) or can Construct do all this anyway? (I've not been through every single event yet so I might be mistaken)...

Also I'm a bit confused about the way angles are implemented, with 0 being right rather than up like I was used to. Will this cause problems when calculating rotations and inertia and all that? Furthermore it all has to work with delta time, have acceleration/deceleration for rotation as well as the same for movement itself.

Any ideas would be helpful, it's been a while since I've looked at any maths in detail :D

Cheers :)
Back to Top
7,061 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jun 2010 at 6:55pm
For that type of movement only addition and subtraction of vectors are needed. No need for dot or cross product although those are easily implementable.

Here's an example for you viewing pleasure:
[url:6qzcubic]http://dl.dropbox.com/u/5426011/examples/asteroidsMovementEx.cap[/url:6qzcubic]
Back to Top
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jun 2010 at 7:21pm
Absolute genius, thanks mr. hound :D

I love it, it's got a great feel to it, I've just added some additional private variables 'ThrustSpeed' and 'RotationSpeed' and adjusted the events so that the numbers 100 and 200 should be easier to play around with. Any idea how I could get the rotation to decelerate when the left/right arrow isn't being pressed? It'd be good to be able to prevent the ship spinning out of control so easily :D So that the ship keeps moving in the right direction due to it's inertia, but the player can point it in the direction they want it to move more easily... I suppose that's more 'arcade' control than real physics but I'd like to play with the options :D
Back to Top
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jun 2010 at 7:59pm
I was looking for a way to implement this explanation but I never could get my head round C++ code examples having really understood OO programming :S

[url:io9vgazq]http://www.gamedev.net/community/forums/topic.asp?topic_id=183827[/url:io9vgazq]
Back to Top
7,061 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jun 2010 at 8:24pm
Actually the 200 and 100 are linear and angular acceleration, not speeds.

For angular deceleration:
[code:3q26kvpc]+ MouseKeyboard: [negated] Key Left arrow is down
+ MouseKeyboard: [negated] Key Right arrow is down
-> Sprite: Subtract 2*'AngularVelocity'*TimeDelta from 'AngularVelocity'
[/code:3q26kvpc]
2 is the deceleration amount .

On a side note the physics behavior is way better suited for this type of movement, as it takes very little to set up.
Back to Top
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jun 2010 at 9:01pm
[quote="R0J0hound":s3mdwcve]Actually the 200 and 100 are linear and angular acceleration, not speeds.[/quote:s3mdwcve]

Yup haha I figured it out after I'd made the post, sorry for that :P

Thanks for the additional help, it works quite nicely :D I considered using the physics behaviour but as with anything that relies on an external library of some sort, bugs are unfixable until someone else fixes it, plus I can better understand the maths behind it all this way. I might stick the physics behaviour in there too and compare :D
Back to Top
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Posted: 21 Jun 2010 at 2:04pm
I managed to piece something together using some things I learned browsing the forum, seems the physics behaviour route might be more ideal anyways since the collisions are already handled much better that I could probably implement them :P

[url:3d7p3lo6]http://www.mediafire.com/file/o1zvm0muyjb/Ast_Physics_1.cap[/url:3d7p3lo6]

Any ways to improve this? The torque/rotation doesn't use DeltaTime, I'm not sure about that :S

I don't know, something feels a tad bit jagged and unnatural about the thrust, what do people think?
Back to Top
7,061 Rep
Post Options Post Options   Quote R0J0hound Quote  Post ReplyReply Direct Link To This Post Posted: 21 Jun 2010 at 8:09pm
The nice thing about using behaviors is you don't need to worry about TimeDelta, because it's handled within the behavior.

You can simplify your events and it will behave exactly the same and be more readable:
[code:1fvwdf3w]+ MouseKeyboard: Key Up arrow is down
-> Sprite: Set force Sprite.value('Thrust') towards (Sprite.X + cos(Sprite.Angle), Sprite.Y + sin(Sprite.Angle))
+ MouseKeyboard: Key Left arrow is down
-> Sprite: Set torque 0-Sprite.value('Rotation')
+ MouseKeyboard: Key Right arrow is down
-> Sprite: Set torque Sprite.value('Rotation')[/code:1fvwdf3w]
Back to Top
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Posted: 21 Jun 2010 at 9:31pm
Ah I wasn't aware of that, that's made things a lot easier :D

It looks much more readable now, cheers again for the help :D It's taking me a while to get my head round the physics behaviour because a lot of the values (angle damping etc) dont seem to have any effect :S I've been trying to adjust the rate of deceleration/acceleration so the turning is more responsive, yet can't seem to figure if this is possible with the torque values. There are so many implementations on the box2d forum haha :D
Back to Top
1,274 Rep
Post Options Post Options   Quote untune Quote  Post ReplyReply Direct Link To This Post Posted: 22 Jun 2010 at 12:46am
One more little addition here... I've been trying to figure out a method of having a mouselook/turret type of behaviour using physics, where the 'ship' rotates to look at the mouse pointer. I've managed to implement this, using the Angle command to find the correct angle to turn towards, by applying torque... however, the torque overshoots and then constantly 'bobs' the ship back and forth in a swinging motion, never settling on the point it should be aiming at. This obviously makes the control a bit unpredictable.

What I need is a way to slow the rotation down as it approaches the correct angle, so that it stabilises on the angle that points to the mouse pointer. I've looked everywhere all night and everything I have tried to implement has failed... there are some helpful things on the net but they all revolve around normalizing angles using pi - I'm not sure if Construct has defined constants, or the ability to define them? Or if a global float would have sufficient accuracy, etc etc...

This was the most useful reference I found [url:ju8c9356]http://stackoverflow.com/questions/2617476/physics-game-programming-box2d-orientating-a-turret-like-object-using-torques[/url:ju8c9356]

I'm off to London til Thursday so I can't carry on working on this, but any ideas would be appreciated so I can get cracking when I return :P
Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down