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 / Trouble with 3D Physics going to sleep

Author
Message
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 2nd Jan 2016 18:30
I have a problem with the 3D Physics in my pool game going into sleep mode. When this happens, I can no longer apply physics to my rigid bodies. I have to delete and recreate the physics objects before I can apply forces to them.

Here is a video of the problem:


Now I know I can deactivate sleep mode, but them they never stop moving. When they're reset they eventually start moving on they're own, which isn't good for a pool game.

Any ideas how I can fix/get around this issue?
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 2nd Jan 2016 23:44 Edited at: 2nd Jan 2016 23:56
By default the Bullet Physics Engine puts dynamic objects to sleep after a certain amount of time of a lack of a certain amount of movement.
This amount of time can be changed with SetObject3DPhysicsDeactivationTime().
The threshold of the amount of movement that starts the deactivation timer can be changed with SetObject3DPhysicsSleepingThreshold().

P.S. To get the balls to roll correctly you will need to tweak the friction coefficient for the balls(dynamic) an the table(static) to get the best results.
Also set the restitution for the balls and bumpers to get the correct bounce back.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Jan 2016 00:48 Edited at: 3rd Jan 2016 00:51
I know about the deactivation timer, and the restitution, but I didn't know about the friction coefficient thanks.

As I said in my initial post, I know I can deactivate the sleep / increase the threshold, but then the balls (lol) start moving without any external forces, which is bad. The video below will show as soon as it uploads..


This shows the issue. All balls (lol) start moving down the screen slowly when they shouldn't. This is without any forces being applied at all, right after a creation at the start of the program, or a reset.
The code I use to create the baize is as follows, and as you can see, it's a simple plane rotated 90 degrees to be flat.



I don't want to increase the sleep time as it introduces these issues, but disabling 'CanSleep', and re-enabling it when you hit the white ball doesn't reset the sleepiness.

I guess what I'm saying is that I need the physics bodies to sleep between shots as you'll, but become enabled again when forces are applied to them, either directly with the SetObject3DPhysicsXXXXXVelocity or indirectly when hit by moving bodies.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Jan 2016 00:53
Or are you saying I need to tweak the friction to slow the balls down, as they don't actually seem to stop moving when hit...
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 3rd Jan 2016 01:21
I 'll start with your code snippet.



Quote: "Or are you saying I need to tweak the friction to slow the balls down, as they don't actually seem to stop moving when hit..."

Yes, you need to tweak the friction and the rolling friction of the balls and the table to get more realistic results.
I can not see the video its private. You do not want to deactivate the sleep mode only adjust if you are not getting the results you want.
All dynamic objects that are put asleep by the physics engine will wake up and become active when another moving dynamic object gets near them
or a force is applied to them. Can you post the whole code snippet so I can run it and adjust it to help you? What are you setting the gravity too?
Did you change the scale factor?


The coffee is lovely dark and deep,and I have code to write before I sleep.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Jan 2016 13:02
Ok, I've removed the SetObjectShapeBox line, which hasn't really made a difference. I still haven't tweaked the friction yet, but I will do. I'll allow sleep mode again based on your suggestion as I do understand leaving it on will be a drain on cpu, which then makes the problem of the balls (lol) not becoming active after about 3/5 seconds.

As for the video, it isn't private, it's unlisted. It may not have fully uploaded when you tried to view it.

I reset the gravity, but only to default. (As I like to see in the code what the value is.) I don't change the scale, but you'll see in the code snippet I PM you.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Jan 2016 14:41
emm, how to add a force or impulse to a object???
AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 3rd Jan 2016 15:40
Mobiius

I replied to your PM. I see in the video that the balls are rolling after reset, I could not duplicate this with the code you sent me.
The code snippet did not show shooting the Q ball at the rack of balls.

Quote: "emm, how to add a force or impulse to a object???"


SetObject3DPhysicsLinearVelocity() and SetObject3DPhysicsAngularVelocity()
The coffee is lovely dark and deep,and I have code to write before I sleep.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 3rd Jan 2016 16:55
@Stab in the Dark software
just Velocity ?
AGK (Steam) V2.0.16 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 3rd Jan 2016 17:08
Quote: "just Velocity ?"

Yes just velocity in this version of AppGameKit 3D physics.
Do you need a different way?
The coffee is lovely dark and deep,and I have code to write before I sleep.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 3rd Jan 2016 18:16 Edited at: 3rd Jan 2016 18:16
You just need to stick a bit of cardboard under one of the legs.


V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Jan 2016 21:41
Quote: "The code snippet did not show shooting the Q ball at the rack of balls."

The snippit does show that, but that's the issue I'm having with the bodies sleeping!

Press space to reset the balls, then left click within 2 seconds and the white ball will move. As long as balls are moving or you click within 2/3 seconds it will move. after this time, they will sleep and will no longer be affected by forces.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 3rd Jan 2016 23:47 Edited at: 4th Jan 2016 17:16
Try this code. Sorry about the confusion.



When I originally wrote the velocity commands I was waking the object from sleep mode before applying the force.
I had forgot that I changed it to allow the user more control. In the code above I wake up the Q ball before applying the velocity.
You do not need to wake up the other balls as they will automatically become active once the moving Q ball gets close enough.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Jan 2016 09:55
That's got it! Many thanks!

Login to post a reply

Server time is: 2024-09-29 09:26:38
Your offset time is: 2024-09-29 09:26:38