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 / 3D Physics Pinball Flipper

Author
Message
Hughbus
AGK Backer
6
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 30th Jan 2018 13:44 Edited at: 30th Jan 2018 14:26
Hey Everyone,

Been struggling with the 3d physics trying to do what I thought was simple (I have successfully done it with the 2d Phyics before)

I'm trying to make a pinball flipper mechanism. <y approach has been to create a hinge joint, with angle limits. But from here, all my approaches seem to not work. Setting impulses, clamping the angle, setting the hinge motor velocity in the main loop seems to stop the physics from updating. Not sure how to best tackle this now, hopefully someone here can help

I didn't go the kinematic body route because the rotating at the flipper at a "realistic" speed caused spheres to not collide more often then not. I assume since updating the rotation values is limited by the game update time versus physics which updates sub frames?

Here is the basic setup of the flipper, with "pin" object to pivot around, etc.


Hope a wise AGK'er can help

Attachments

Login to view attachments
Hughbus
AGK Backer
6
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 30th Jan 2018 14:50
Just as an update while I work through this. THis is a version that uses a kinematic flipper, and yup the ball passes through most of the time. Up arrow to spawn balls, click to use the flipper

Attachments

Login to view attachments
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Jan 2018 22:35 Edited at: 30th Jan 2018 22:35
I have experienced tunneling when the scale of the model is too small.
Attached is a project i have given up on. I have scaled the models up considerably and still experience tunneling.
Ctrl and Alt keys for flippers and plunger

Note that there is a delay at the start where it separates a large 3D scene into it's individual model parts so it can animate and/or control each individual element.
After you run it you will see that there is a "table" folder in your documents directory that contains all the individual models

Hope it helps

Attachments

Login to view attachments
Hughbus
AGK Backer
6
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 31st Jan 2018 00:13
ah thankyou so much for the tips. I hadn't considered scaling as part of the issue but it does help. You are right, there is still a lot of tunnelling that can occur, especially if you start to make flippers move at realistic speeds, etc. Its a shame the continuous collision features of bullet aren't integrated to help prevent tunnelling.
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 31st Jan 2018 03:50
Quote: "Its a shame the continuous collision features of bullet aren't integrated to help prevent tunnelling. "


It is using Constant Collision detection. You may not be using the correct scale factor.
The coffee is lovely dark and deep,and I have code to write before I sleep.
CJB
Valued Member
16
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 31st Jan 2018 07:20
I've seem posts where people mention the need to calculate multiple update 'frames' for the physics between each render and swap to give better physics accuracy. Worth a try?
Hughbus
AGK Backer
6
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 31st Jan 2018 12:22
@StabInTheDark good to know! If that's the case then probably a big part of the problem is that its a kinematic body versus being dynamic. Is there a clear way that you can think of to use hinges and motors to actuate the flipper between say -35 and +35 degree angles?
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 31st Jan 2018 15:46 Edited at: 31st Jan 2018 16:15
Hughbus,You are over thinking it. You would not use hinges and motors. You would not use a dynamic or static.
The flipper would just be a kinematic object which you would pivot with the rotate object commands.
Have you looked at BlinkOK's project he posted above, I have tested it and do not see any tunneling.
FYI: kinematic objects can impart large forces on dynamic objects(ball) so you may need to lower the
max linear velocity of dynamic objects for your project. If dynamic objects move too fast they can
tunnel thru other physics objects. Also limit your framerate to 60 FPS.

Quote: "I've seem posts where people mention the need to calculate multiple update 'frames' for the physics between each render and swap to give better physics accuracy. Worth a try?"


CJB, That would be trying to manually increase the resolution of the physics which would give unstable results.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 31st Jan 2018 16:14 Edited at: 31st Jan 2018 16:17
I took a look at your Kinematic example above and discovered your problem.
When you call Create3DPhysicsKinematicBody( flipper ) for your model AppGameKit by default
creates a box collision shape. If your model is offset from origin when exported from
the modeling program the box collision shape will be inaccurate as it will be not offset.
So you need to use the convex hull shape instead, code change below.



So what was happening was not tunneling but an offset collision shape.
In your example the ball no longer tunnels but does bounce over the flipper sometimes.
Do not make your ball smaller at the default scale factor or you will get tunneling.
Hope this helps.
The coffee is lovely dark and deep,and I have code to write before I sleep.
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Jan 2018 19:49 Edited at: 31st Jan 2018 19:55
I see tunneling. It doesn't happen when you think it would. When it's flying around between the bumpers it doesn't tunnel but occasionally, when you let the ball roll to the end of the flipper and then flip, it will tunnel through the flipper.
As i said it doesn't happen very often but it does happen often enough to put me off playing it
Rick Nasher
2
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 31st Jan 2018 23:06
@blink0k
This is such a nice project, can't help but feeling it deserves a better faith.
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Jan 2018 23:41
Thanks rick. I appreciate your advice and support but i have other things that i have left on the shelf to deal with.
Rick Nasher
2
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 1st Feb 2018 01:01
@blink0k
Know what you mean
Anyway many thanks for sharing, who knows in future I'll try something like this(always had in my mind ever since Pinball Fantasies on the Amiga), then will really come in handy as an example/how to.
Hughbus
AGK Backer
6
Years of Service
User Offline
Joined: 24th Oct 2013
Location:
Posted: 1st Feb 2018 08:27
Even after those changes, the tunnelling at the tips is still what I see in my project as well. The flippers move fast enough that the tips can completely bypass the ball between frames.
Rick Nasher
2
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 1st Feb 2018 18:55
When the ball is hitting the top bumpers and sometimes gets in a bouncing frenzy, it goes very fast then it appears a bit as if the ball has too much energy for it to be natural.

I'm a physics beginner, but could this all perhaps be related to a wrong setup of velocity/ mass/ friction values?
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 1st Feb 2018 18:59
Like I said make the ball and flipper larger or lower the scale factor because there is a minimum size at the default scale factor.
If you are going to program with physics you need to understand that tunneling is a reality of
using a physics engine and all physics engines have this problem. AppGameKit is setup correctly to minimize
tunneling but you as the coder must use it correctly. It is possible to move a kinematic object too fast
since its speed is not governed by the physics engine and could result in tunneling. So you the programmer
needs to slow down the flipper to prevent tunneling.


Quote: "You must create the Physics world before calling any other physics commands. Create3DPhysicsWorld Creates the physics world using the default scale factor of 40. This function will create the physics world with a different scale factor. The scale is not the size of the world, it is the factor by which all the data passed in is scaled down by to convert it to the Bullet Physics scale for the physics calculations. Then the data from Bullet is scaled up before it is passed to the AppGameKit 3D world. The default scale factor will be correct if your average character size is 72 AppGameKit units tall. Then the default gravity of -10.0 meters per second on the Y axis will give the correct visual result. The Bullet Physics solver has a minimum size for objects. Objects below this size will cause instability with the solver. At the default scale factor of 40 the smallest dimension that the solver can handle is about 3.5 AppGameKit units. To calculate the scale factor first determine your character's height in meters, a character of 72 units tall would be 1.8288 meters (or 6ft). Then divide the character's height in units by the characters height in meters, for this example the scale factor would be (72 / 1.8) = 40."
The coffee is lovely dark and deep,and I have code to write before I sleep.
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Feb 2018 20:43
What i was saying is it doesn't seem to be the speed of the ball (or the flipper) that causes tunneling.
When the ball is bouncing off the bumpers it moves much faster than the flipper does when it moves and it only occurs intermittently.
So i can only assume it is a bug (on my part or the physics system)

Login to post a reply

Server time is: 2020-04-05 14:23:31
Your offset time is: 2020-04-05 14:23:31