Ball Physics vs CollisionTree Suitability

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Ball Physics vs CollisionTree Suitability

Hi All,

I'm making a marble run / monkeyball type game and we have for each level a triangle mesh - this works well "most" of the time.

I'm having problems with a 'half pipe' / curved wall type shape vs a sphere. The sphere acts as though it approaches the wall, hits on of the lower triangles, bounces off that at an angle (usually backwards and up slightly). The desired behaviour is to climb up the surface and perhaps start to roll back again if you didn't have enough speed.

This is an example of the sort of shape/reaction I'm describing:

Example of the geometry 'in game':

I'm not sure how best to solve this - do we need to raycast in front of the ball based on it's velocity and perhaps aply some sort of 'forced roll' or 'lift'? The level geometry is reasonably triangulated, I don't expect a smooth roll from only 2 triangles but the original monkeyball game ran on a gamecube and gave excellent results on this same geometry - the level being used is copied from the game directly. So I'm curious how best to get that same effect?
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Re: Ball Physics vs CollisionTree Suitability

The are few way to solve those issues.
Can you make a short video, so that I can see the problem.?
I assume you are using a current version of the engine.
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

Here is the eassiest trick.
This is similar to a pinball game that use newton.

If your game does not uses an excessive number of active bodies, say fewer that 200, static do not count.
The easiest thing is to initialize the engine with say five sub steps.
That will be an effective 300 fps if you game run at a fix 60 hertz simulation.
Those were the setting for pinball and is work very well, and pinball the flipper move really really fast.

Please try that ant let me know if is better.
The improvement should be a near perfect roll.
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

Hi, thanks for the response - apologies for the delay in responding, currently struggling with uploading a video in the right format.

Setting substeps to 5 (the number of active bodies is extremely low... probably only 5 or six if that) makes a huge improvement and you're right - it seems to solve the problem entirely. It does however create a new issue that the game is in slow motion (ie, 5 substeps gives the impression of 20% speed). Do I need to call the update function 5 times during each loop to balance this out or is the engine supposed to handle this internally? (Otherwise I'm not sure how this function is different to calling update with a smaller timestep).

Should I be doing something else as well as this?
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Re: Ball Physics vs CollisionTree Suitability

Otherwise I'm not sure how this function is different to calling update with a smaller timestep

is different is that normally games are tuned to run at a specificity frame rate and changing it that parameter as a after though is a big deal if not planned ahead of time, plus there are few step that are shared across call. but using this method you can change the physic fidelity without warring of having to change you game logic.
of course you can do it by just running the update in loop, and in a small game is probably the same thing. in the pass this was how was done, but with multicore thread a multicores, and asynchronous update this made a huge difference.

you should just call the update with the same time step as if there was not sub stepping, the engine does by itself, here is a pseudo samples
Code: Select all
`int maxSteps = 5;float timestep = 1.0f / 60.0fNewtonWorld* world = NewtonCreate();NewtonSetNumberOfSubsteps(world, maxSteps);// game loopwhile (isRrunning){   NewtonUpdate(m_world, timestep);   //run rest of game logic, AI, render etc}`

the number of sub step is independent of the simulation time step.
also notice that the callback if you have any you should use the time step passed in the arguments if the functions, not the time step you pass the newton update,
so if you are computing you game forces in a force and torque call back you should use the time step pass by the engine.
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

I'm not sure why I'm seeing different behaviour in that case?

I currently have physics completely separate from rendering and other things, the physics and general game 'update' loop is run 60 times per second.

If I set the newton timestep using NewtonSetNumberOfSubsteps to 5, the physics run in 'slow motion' and pressing 'forward' to move gets to a speed of 3.1ms after a few seconds. Without calling this function everything seems normal and speed reaches around 9ms after pressing forward for a second or two.
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Republician Intelectual.

There will be different behavior but not that much, that's what numerical integration is all about, the smaller the time step the more it approximate the ideal integration.

but in your case my guess I think you have the default Drag coefficients, you should set them to zero or to a very small value when you make the dynamics bodies.
Code: Select all
`   dVector drag(0.0f);   NewtonBodySetLinearDamping(m_body, 0.0f);   NewtonBodySetAngularDamping(m_body, &drag[0]);`
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

Setting steps to 5 makes the game run in slow motion with the maximum speed considerably lower than not doing this.

If however, I don't set substeps and instead call newtonUpdate 5 times per update loop (with 0.16/5 instead of 0.16 ie 60fps), (and set damping to 0.001) I seem to get smooth handling of curved edges and the behaviour expecting for game speed. This seems to be the best solution so far although runs counter to what you were saying about it being handled internally. Continuous collision mode being set on the sphere dosen't seem to have any effect on this issue.

As a related side question - to move static level geometry (moving platforms etc) I've been setting the matrix of the collision body. Will this break under this style of running? I'm also curious in that, if I want to have rotating geometry does this need special handling?
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Re: Ball Physics vs CollisionTree Suitability

I did not say is different, I said is more efficient when doing things like asycronous updated. But even that you can handle on you side. Many people do, but some do not and expect the engine to provide that functionality.
If you get it but running the pure in a loop the that's the solution.

The continue collision does not help there because your case the curvature of the be is what is changing, vs is for hobbies that move fast but that are not already in contact with other body.

On the moving platform, if you move it from inside a newton update, the is improve a great deal with the smaller time step.
The accuracy of the simulation improve with the square of the step side,.
Is like this say the difference between an ideal integration step is E, making the time step 5 time smaller reducesctha error by a factor of 25.

It comes from the definition of a simiimplicy intgreation step,
x = x0 + d'* st + E(dt^2)

if dt is dt/5 them E becomes E(dt^2)/25
not vs can beat that.

The moral is that if it was working at dt it can only be better at dt/5 so long you move your platform at simulation time.
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

I may have misunderstood this part:
Julio Jerez wrote:
you should just call the update with the same time step as if there was not sub stepping, the engine does by itself, here is a pseudo samples
- this appears to imply you simply call 'NewtonSetNumberOfSubsteps' and the engine handles it all internally which is clearly not the case.

The curved surfaces are working quite well now so that's positive. I just need to figure out rotating level geometry. Things moving positions work well but anything that spins or turns seems to 'bounce' the ball - presumably because the geometry beneath the ball teleports between positions. Not really sure if that's solvable.

For example a ball inside a large cylinder that's lying on it's side - spinning the cylinder at any decent speed will make the outside geometry change hugely even at a physics update of 100fps.
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Re: Ball Physics vs CollisionTree Suitability

- this appears to imply you simply call 'NewtonSetNumberOfSubsteps' and the engine handles it all internally which is clearly not the case.

you didn't, that's how is suppose to work. if it does not, then there most be some bug, I will check it out.

on the platform, I thought we where talking about small translation movement of static bodies.
If a body rotates and is very big them yes it will make huge displacement, but that can be solved as well.

There was a game Ship Simulator where the ship is a huge static body, that translate and rotates, for that there is a way to manually integrate static or kinematic bodies in such way the velocities are provided at the moment of collision.

I do not remember the details now, but if you make a video so that I can see the kind of scene we are talking about, them we can set a test demo in the sandbox to work out a solution.
It is not a difficult problem.
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

Can you play the sandbox?
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

This is the sort of scenario:
If you imagine a small ball inside the red can.. the can is spinning and the ball would fall to the bottom and gravity would keep it there but - the spinning of the cylinder would make it climb towards the side. If that isn't clear I'll try to find a better picture. If a ball was placed on the outside of the blue can the player would have to fight to stay on top. I know this can be done with a cylinder primitive but we're putting holes in the sides of the can and having bumps etc.. so it's a triangle mesh which is a cylinder with holes. The same problem will come up in lots of other levels though - not all moving platforms are simple elevators, sometimes platforms turn or spin as well as simply apply a translation.

Another issue, the 'faceattribute' that you pass to NewtonTreeCollisionAddFace isn't passed to the collision callback in the material - NewtonMaterialGetContactFaceAttribute returns 0 no matter what I seem to do. I should probably create another thread rather than keep asking questions but I feel I'l pollute the forum if I start a new thread for every single query.
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Re: Ball Physics vs CollisionTree Suitability

I am confused now, you mentioned elevators that can be move kinematically, by them you show a picture of two teen can, one opened that seem to be best represented by a dynamic rigid body with a compound collision.
Julio Jerez
Moderator

Posts: 10954
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Ball Physics vs CollisionTree Suitability

Perhaps I've not managed to explain - I have not said they're elevators. I said "not all moving platforms are simple elevators" meaning that I need more complex behaviour than simply moving a flat platform up/down or left/right.

When talking about a cylinder, I agree about a simple convex collider and I said the cylinder shape can be used for a ball on the 'outside' but if you imagine a ball 'inside' the cylinder then it's not so simple.

This is the sort of triangle mesh I'm talking about:

There are holes / bumps in the surface for the player to avoid and the player object is placed inside at the bottom and the entire thing turns slowly.

P.S. with careful tuning of movement speeds and taking three NewtonUpdate per game loop the 'rolling on curved surfaces' seems to be working quite well now.

EDIT: I found an example of the sort of thing I mean in this video (apologies for loud music): http://www.youtube.com/watch?v=ryrgfLfNUko&t=66m45s
anothertime12

Posts: 17
Joined: Tue Nov 27, 2018 11:28 pm

Next