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.