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:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
51
S
24
G
30
Posts: 534
Reputation: 19,620

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
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

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
55
S
29
G
19
Posts: 1,520
Reputation: 25,670


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests