'Thrust' Physics

For questions about using Classic.

Post » Tue Jun 22, 2010 1:03 am

weird, I was just doing this today for my own project

set torque towards object
at a force of anglediff(.angle,angle(ship.x,ship.y,mousex,mousey))
multiply that whole thing by something or divide it by something until it's at a good looking amount
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Jun 22, 2010 7:51 am

Very cool lucid, it seems to work pretty well if the changes in angle are small, but if you make anything bigger, lets say a 90 degree swing, you still get a pretty big overshoot of the intended target - maybe some of the physics settings need to be different in order to have a more responsive torque behaviour? Or is it just unavoidable when using the physics behaviour to have objects swing all over the place when torque is applied? :D
B
15
S
6
G
6
Posts: 103
Reputation: 2,968

Post » Tue Jun 22, 2010 10:14 am

Would clamp help here? Or perhaps lerp?
B
2
S
2
G
3
Posts: 105
Reputation: 1,510

Post » Thu Jun 24, 2010 7:38 pm

Finally got an example for a physics turret working:
[url:3fge8wk2]http://dl.dropbox.com/u/5426011/examples/PhysicsTurret.cap[/url:3fge8wk2]
and tweaked so it works with multiple turrets:
[url:3fge8wk2]http://dl.dropbox.com/u/5426011/examples/multiPhysicsTurret.cap[/url:3fge8wk2]

The only drawback is the turret's inertia needs to be calculated (which I do in the first second). Also the calculated inertia is not 100% accurate so the turrets jitter a bit when pointing at the target.

-enjoy
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Fri Jun 25, 2010 9:33 pm

That's a really cool example, the maths are getting more and more complex eh :P It's a shame about the jitter, I've been pondering how exactly to remove that. I'm still not sure about the whole radians/angles thing... since all of Box2d's calculations are implemented using radians (which is the proper way to go in a mathematical sense) yet everything in the physics behaviour and construct in general uses degrees...

I'll just have to keep trying stuff and see what comes of it :P Maybe there's a way of implementing it by setting the angular velocity as opposed to using torque
B
15
S
6
G
6
Posts: 103
Reputation: 2,968

Post » Fri Jun 25, 2010 9:42 pm

Also found this which outlines the necessary formula from the looks of it - however it might also use parts of Box2d that aren't implemented in the Construct physics behaviour... unless there's a workaround?

[url:1wfh9zuz]http://www.box2d.org/forum/viewtopic.php?f=3&t=3071[/url:1wfh9zuz]
B
15
S
6
G
6
Posts: 103
Reputation: 2,968

Post » Fri Jun 25, 2010 10:02 pm

A solution for the jitter would be to stop the motion and point to the target when the angle difference and angular velocity are lower than some thresholds.

Add this event to the "targeting" group:
[code:1pqycuqz]+ System: AngleDiff(turret.Angle, turret ('target')) Lower than 0.5
+ System: abs(turret[Physics].AngularVelocity) Lower than 0.2
-> turret: Set torque 0
-> turret: Set angular velocity to 0
-> turret: Set angle to 'target'[/code:1pqycuqz]
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Fri Dec 10, 2010 3:54 am

Going back to the original topic of this post, (and reviving an old thread, sorry)--

I modified the original file as per ROJOhound's suggestions here:

[quote="R0J0hound":1xvb5vvc]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:1xvb5vvc]+ 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:1xvb5vvc][/quote:1xvb5vvc]

But I'm still confused as to how to use behaviors to slow the ship down QUICKLY once you let go of either the left or right arrows... There are two private variables in this CAP. Thrust and Rotation. Should I be trying to subtract from Rotation over time once the left or right key is no longer pressed??

How would that look?

Sorry for the new-b questions... It's just that I am, in fact, a new-b... Just found this site yesterday. Trying to learn what I can.

Thanks!

Also, for completeness sake, here is the file I modified according to the above suggestions:
[url:1xvb5vvc]http://www.mediafire.com/file/yvlw4fo5sfqfuj5/Ast_Physics_4.cap[/url:1xvb5vvc]
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Fri Dec 10, 2010 5:05 am

use custom movement for thrust based physics.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Fri Dec 10, 2010 6:23 am

[quote="Davioware":2o396juc]use custom movement for thrust based physics.[/quote:2o396juc]

I know a little about Custom Movement... I went ahead and added it to the Sprite. There are settings for adding friction to motion rotation. But that doesn't seem to be getting me anywhere...

Is there a separate Custom Movement for thrust based physics that I just don't know about??

I can get the ship to STOP COLD when I release the left or right key -- by adding"

[code:2o396juc]+ MouseKeyboard: [negated] Key Left arrow is down
+ MouseKeyboard: [negated] Key Right arrow is down
-> Sprite: Set angular velocity to 0[/code:2o396juc]

But again... I just want it to slow down the rotation faster once you let go of the left or right key.

I'm happy to go check out any tutorials/examples/faqs or whatever if you could point me in the right direction... Thanks!
B
4
S
1
G
2
Posts: 64
Reputation: 980

PreviousNext

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests