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 / Physics Bug?

Author
Message
OceanJeff40
11
Years of Service
User Offline
Joined: 29th Nov 2012
Location: Ocean Shores, WA
Posted: 21st Jul 2016 17:22
So I was just playing around with the Physics engine, and I added a few lines of code to the sample, here it is:

// display a background
CreateSprite ( LoadImage ( "background4.jpg" ) )

// load an image
LoadImage ( 1, "small_silver.png" )

// create 5 sprites
CreateSprite ( 1, 1 )
CreateSprite ( 2, 1 )
CreateSprite ( 3, 1 )
CreateSprite ( 4, 1 )
CreateSprite ( 5, 1 )

// set their positions
SetSpritePosition ( 1, 0, 0 )
SetSpritePosition ( 2, 50, 0 )
SetSpritePosition ( 3, 100, 0 )
SetSpritePosition ( 4, 150, 0 )
SetSpritePosition ( 5, 200, 0 )

// turn physics on
SetSpritePhysicsOn ( 1, 2 )
SetSpritePhysicsOn ( 2, 2 )
SetSpritePhysicsOn ( 3, 2 )
SetSpritePhysicsOn ( 4, 2 )
SetSpritePhysicsOn ( 5, 2 )

// alter default gravity
SetPhysicsGravity ( 10, 10 )

// main loop
do
// update screeen
for i = 1 to 5
SetSpriteX ( i , (i-1)*50 )
next i
Sync ( )
loop

This is the gravity sample.

Anyways, you can see what I'm doing is trying to keep the blocks stable on the horizontal axis (x), and let the physics do what it wants with the Y axis.

However, when I run this, the blocks don't move at all.

Is this an obvious bug? Or am I missing something?

Thanks,
Jeff
Hi
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 22nd Jul 2016 09:41
some non physics commands disturb the physics.
maybe you can use the CreateLineJoint command?
AGK (Steam) V2.0.20 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd Jul 2016 11:42
I think you'll need a kinematic sprite (If the 2d Physics have it)

Also, don't forget to use the code tags around code snippits.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 22nd Jul 2016 12:31
I wonder if setting the position on any sprite would reset its physics velocity - might be worth storing the velocity, then setting the X position, then set the velocity to what it was before - maybe setting the X velocity to 0 as well to be on the safe side.
The code is dark and full of errors
OceanJeff40
11
Years of Service
User Offline
Joined: 29th Nov 2012
Location: Ocean Shores, WA
Posted: 23rd Jul 2016 02:47
Van B, good idea, I'll try that.
Jeff
Hi
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 23rd Jul 2016 07:47
VanB is 100% correct. When it comes to using the physics commands, any command outside the physics commands that effects a sprite will completely wipe all physics from the object until the next physics call. This is coming from experience coding an Asteroids clone. When I started to write code for a screen wrapper function, I discovered that I would have to store the original velocity x/y and acceleration x/y variables before re-positioning the sprite, than reapply the velocity and acceleration to the sprite. I got perfectly smooth movement every time.
My workstation was destroyed in a fire, help me out and get free media for AppGameKit and Game Guru: https://www.gofundme.com/bfpm0g

Login to post a reply

Server time is: 2024-11-25 03:38:36
Your offset time is: 2024-11-25 03:38:36