Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / 2D Physics screen wrap/teleporting?

Author
Message
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Dec 2017 13:42 Edited at: 2nd Dec 2017 13:44
Hey,
Until now I have never used the AGK(Box2D) physics commands. I usually simulate my own but with a current test project, the physics was getting more and more intense, so I decided to resort to AGK's physics instead.

My game world is wrapped on all four edges, so when you go off the left you come back on the right etc. With my own physics it was easy enough. Just change the sprites position,essentially teleporting the sprite, and all the physics properties were maintained. But now with AGK's physics when I teleport the sprite the velocity and angular velocity is stripped and the sprite becomes staitionary.

The question is: How do I teleport the sprite and maintain all physics properties? Do I have to store them all and then reapply?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Dec 2017 14:51 Edited at: 2nd Dec 2017 14:53
Quote: "when I teleport the sprite"

how do you do this?
have you an example source code of your problem?
you also disabled all physics walls SetPhysicsWallLeft ( mode ) ?
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Dec 2017 15:16 Edited at: 2nd Dec 2017 15:18
Quote: "how do you do this?"

With SetSpritePosition()
Quote: "you also disabled all physics walls"

Yes I did.

Here is an example of the screen wrap (teleport) for the 'ship' sprite:


screen.l/r/t/b holds the dimensions of the wrapable area
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Dec 2017 15:54 Edited at: 2nd Dec 2017 15:58
Here is a complete code example:

In that, the sprite falls due to gravity and when it reaches the bottom of the screen it is 'teleported' to the top.
It falls again because gravity continues to affect it but the momentum that it had is removed so it starts falling again from a stationary position.
What I want to do is retain the momentum that the sprite has before the telport.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Dec 2017 16:09 Edited at: 2nd Dec 2017 16:11
yes, seems the velocity go zero, but you can save & restore
Quote: "
vx=GetSpritePhysicsVelocityX(ship.spr)
vy=GetSpritePhysicsVelocityY(ship.spr)
SetSpritePositionByOffset(ship.spr, GetSpriteXByOffset(ship.spr), screen.t)
SetSpritePhysicsVelocity(ship.spr,vx,vy)

see also
GetSpritePhysicsAngularVelocity
SetSpritePhysicsAngularVelocity
"
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 2nd Dec 2017 16:21
Quote: "but you can save & restore"

Thanks Markus, that's what I suspected. It just seems very counterintuitive.
It's easy enough to implement but I would have thought it would be an option that can be turned on/off where the default would be not to reset the physics.

Very odd!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Dec 2017 20:04
agree, because you set only a new position it not should reset any physics values.
maybe can @paul explain this manner.
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)

Login to post a reply

Server time is: 2024-11-24 06:42:16
Your offset time is: 2024-11-24 06:42:16