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 Studio Chat / possible physics issue when turning physics on?

Author
Message
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 5th Aug 2023 16:41
it seems that after i turn physics on, on my sprites every so often it breaks. It sends the sprite off screen and jumps around where if i try to get its x position it comes out as - nan. the idea is theres a dummy sprite im using for collision and also the actual sprite fallows the position of this dummy sprite.These are the only physics i set.

other then that this is how i set my positioning,

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 5th Aug 2023 23:12
there's more going on in the vid than the 4 simple lines of code you supplied.

from the vid, it looks like you continue to position the sprites and sometimes overlapping one another. repeatedly. what else is going on @ that time?
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 6th Aug 2023 02:13 Edited at: 6th Aug 2023 02:16
these are the two functions for controlling the spawning and movement of them

this bit i recently added to deal with the issue temporarily

i commented out the set sprite shape and also made them always spawn not " climbing" by setting spawn to 2
JosephB
17
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 6th Aug 2023 15:10
According to the command information for SetSpritePhysicsOn, using SetSpritePosition as a means to move the physics sprite should be used sparingly. Using forces upon a physics sprite is the way to move them. Following is some of the SetSpritePhysics on information:

SetSpritePhysicsOn
Description
Sets the sprite up for automatic collision using the built physics system. Once you have set a sprite to be controlled by physics you should use SetSpritePosition and SetSpriteAngle sparingly as these will interrupt the physics motion of the sprite. You can also use the SetSpritePhysicsVelocity and SetSpritePhysicsAngularVelocity to change the speed and direction of a sprite, but again these will interfere with the physics motion of the sprite. If you wish to influence the position or rotation of a physics sprite you should use the force and torque (rotational force) functions where possible, these will maintain smooth physics motion.

The mode parameter lets you choose how the sprite should behave in the physics world. Static means it will never move or rotate, dynamic means it will respond to all collisions and forces it encounters, including gravity and collisions with static objects. Kinematic is a special case which can be thought of as a moving static body, it will not respond to collisions or forces and will continue at its specified velocity forever, but dynamic items will respond to it and effectively be pushed out of the way.
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 6th Aug 2023 15:20
i remember seeing apost of someone who needed to apply a small amount of force when creating the physics object but that might have been only for 3d maybe? i havent used physics much other than to just turn it on and changing the way my sprites move. thank you
dandrews
3
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 7th Aug 2023 00:30
Ive ale found that its only clones of the first sprite that ever have the issue
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 11th Aug 2023 00:55
Note that clone of sprite will not duplicate the physics properties, also JosephB is correct that setting the sprite's position should be done on initial load. Here is quick example showing difference b/w SetSpritePosition() and SetSpritePhysicsVelocity():



Here's the box I used lol:
Automation on Steam now!
Score Table Jr. on Google Play!

Login to post a reply

Server time is: 2024-02-26 10:39:30
Your offset time is: 2024-02-26 10:39:30