Simulate 'wrap' behaviour with physics

Get help using Construct 2

Post » Wed Jun 13, 2012 10:36 am

Hi,

I want to be able to simulate the 'wrap' behaviour for an object that is being moved using a physics force. I understand that teleporting objects by changing their position directly can cause problems with the physics routines so I am trying the following approach:

- when the object leaves the layout then
- store its current physics velocity in instance variables
- set its physics velocity to zero
- teleport the object to the other side of the layout by setting its position

- if the object has a stored physics velocity then
- set its physics velocity to the stored value
- set the stored value to zero

The problem I have is that including the step in bold above causes the physics velocity to be set to zero after the object has been teleported for some reason. If I disable this step then the object gets the correct velocity following the teleport but the event will keep firing and restoring the stored value.

Theres a simple capx showing my problem here.beikul2012-06-13 10:37:54
B
3
Posts: 4
Reputation: 458

Post » Wed Jun 13, 2012 10:47 am

As a small tip, you may want to check the ordering of your events and actions.
Zelda Gamekit (my project)

Example capxs I have made:
Zelda-Style Inventory
Zelda Hearts System

The unwritten "How do I" capx etiquette! Nearly always provide a capx of the problem you have, and try to isolate the problem and/or no capx above 10 MB. :)
B
38
S
19
G
26
Posts: 438
Reputation: 16,581

Post » Thu Jun 14, 2012 11:43 am

Thanks for the suggestion - I had already tried moving the events around but it didn't seem to have any effect.
B
3
Posts: 4
Reputation: 458

Post » Thu Jun 14, 2012 3:54 pm

I don't know why the velocity is changing back to zero but try this: capx (r94)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Thu Jun 21, 2012 1:47 pm

Sorry for the slow reply and thank-you very much for posting that capx.

I can see that you've added an additional test against the player's physics velocity being zero before setting it with the stored value. I can't really see why this is necessary (some quirk of the physics engine perhaps?) but I'm happy it's working.
B
3
Posts: 4
Reputation: 458

Post » Thu Jun 21, 2012 4:15 pm

It says in 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.[/quote]

When you set the physics velocity to 0 it's not updated the very next tick. It seems to take 2-3 ticks before the velocity is actually 0.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, randomly, spcsmrf, Yahoo [Bot] and 26 guests