0 Favourites

Simulate 'wrap' behaviour with physics

  • 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.

  • As a small tip, you may want to check the ordering of your events and actions.

  • Thanks for the suggestion - I had already tried moving the events around but it didn't seem to have any effect.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • I don't know why the velocity is changing back to zero but try this: capx (r94)

  • 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.

  • It says in the manual:

    he 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.

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)