Unpin then apply force

Get help using Construct 2

Post » Fri Sep 07, 2012 3:29 pm

Hi all,

I've been having some issues with the pin behaviour when combined with physics objects.

I want to simply unpin an object then apply an impulse. You can find a .capx here: https://www.dropbox.com/s/ub8squybwbtwvsl/missile%20pin%20test.capx

99% of the time the force isn't applied. When adding a wait, of around 0.1 seconds it launches, though becomes unpredictable across different spec devices.

I've even tried testing for the object not being pinned then applying the force but it makes no difference :(

Any help would be greatly appreciated.thehen2012-09-07 15:34:02
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Fri Sep 07, 2012 4:28 pm

Try putting the unpin action and the physics force action in separate events like this. (Note the boolean to trigger the launch.) I also added an outside layout condition to the the missile. You should probably destroy it (or recycle it) when it goes outside the layout.

B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Post » Fri Sep 07, 2012 4:45 pm

Thanks for the reply. The problem with this is that it continues to fire the physics impulse, rather than just doing it once.

If another system event 'Trigger once' is added, the unpredictability persists.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Sat Sep 08, 2012 10:36 am

I've updated the .capx here to illustrate my point:

https://www.dropbox.com/s/ub8squybwbtwvsl/missile%20pin%20test.capx

This doesn't seem to be related to the bool, but rather the unpinning taking an indeterminable amount of time to actually unpin, despite being registered as unpinned.
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Sat Sep 08, 2012 2:39 pm

From the manual:
[quote]
The Physics behavior simulates physics separately to the Construct 2 layout. Construct 2 will try to keep the Physics and Construct 2 "worlds" synchronised if one changes but not the other, but this can be unpredictable. For example, setting an object's position or angle will cause Construct 2 to teleport the corresponding object in the physics simulation to the object's new position, which does not always properly take in to account collisions. The same is true of using other Construct 2 behaviors at the same time as Physics.

Therefore it is highly recommended to control Physics objects entirely via the Physics behavior (by setting forces, impulses, torques etc.), rather than trying to manipulate objects by Set position, Set angle etc.
[/quote]

It's always unpredictable when you move physics objects without using the physics actions.
You could use a separate sprite for aiming and then spawn the missile when you're ready to launch. physicsPin.capx (r102)

Or the other option would be to rotate it with 'set torque' instead of pinning it.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Sep 08, 2012 4:39 pm

Thanks! That makes lots of sense, I don't know why I was determined to unpin a physics object - spawning a new one works great :)
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests