ball physics

Posted By: Jason Bryant

ball physics - 08/03/03 00:12

This is a small ball rolling project that I have been working on.

Arrow keys: move the ball
mouse move: moves camera
left mouse button: jump
right mouse button: fly

game issues:
1. Occasional collision problems. These have been greatly reduced since adjusting my gravity to more earthlike conditions. However, if you apply force on the ball somewhat perpendicular to a wall, the ball will spin through the level.

2. Odd bounce sometimes upon landing. Sometimes the ball will land and you will spin to the side instead of continuing in the same direction.

Thanks to ventilator for the skybox.

link: http://home.maine.rr.com/twomansoftware/rollyourown.zip

Jason

- please let me know of any problems or suggestions. Thanks.
Posted By: fastlane69

Re: ball physics - 08/03/03 00:31

We're happy for you really we are.....

but.....

This is the wrong forum....

this belongs in the showcase forum....
Posted By: Jason Bryant

Re: ball physics - 08/03/03 00:35

I posted here because this isn't really anything that I'm trying to showcase. I simply wanted to demonstrate physics and physics related issues that I've been having (collision).
The ball does demonstrate nice physics for so easily programmed. The ball is moved solely using the phent_addcentralforce command once per frame, so it's nothing fancy. I have been impressed for the most part with the physics engine. However, I still want to try to help show problems that I am having as to (hopefully) help towards their being improved. I assume if I am having particular problems that others probably are having them as well.

Jason
Posted By: fastlane69

Re: ball physics - 08/03/03 01:25

Dude, not to burst your bubble, but most anyone who visits this forum (physics scripting) can do what you did.

You're not presenting a new technique, nor asking a question, nor posting some insght onto the physics engine.

You say that this will demonstrate the problems with the physics engines yet you pose no new questions, no new bugs, and no new issues.

Everything you mentioned is a well known issue.

So Again, while you're intent may not be to showcase your project, by my understanding of the forums (and I could be 180 degrees wrong on this), this belongs in showcase not here.
Posted By: Jason Bryant

Re: ball physics - 08/03/03 02:17

If you could provide me with a link of these known issues that would be great. If you had read the first post you would see that I've asked two questions. I am not aware of any post by Conitec in reference to spherical physics objects spinning through level blocks. I am also unaware of any post referencing the odd spin that the ball receives sometimes on landing. If you could provide something useful in reference to these, that would be great. By the way, who is the "we" that you are speaking for? You should use "I" not "we". Also, I'm sure that the moderators are quite able to make their own decisions without your useless thrash posts.
I don't understand what you mean when you say burst my bubble.

thanks for reading,
Jason
Posted By: fastlane69

Re: ball physics - 08/03/03 02:31

As to your issues, look at you're own past post about objects sinking "Methods for reducing collision problems?" and spinning "unknown spinning". Like I said, you ain't said nothing new, not even to yourself! [Smile]

My first impression of you post was that you were showing off your current physics project and you were simply listing the issues that came with it. Near as I can tell, these aren't questions. Questions usually end with a ? or require a reply, thing neither of you points asked. You're points weren't phrased in the form of a question, you asked nothing specific about these points, and merely ask us to " please let me know of any problems or suggestions. Thanks. "

Sounded to me like someone showing off his work rather than a person with specific question.

I wasn't aware that your post was merely summarizing the ideas of two of your previous posts.

Sorry for the misunderstand, but be more specific in the future. Just some advice, nothing more, nothing less.

Peace out.
Posted By: Jason Bryant

Re: ball physics - 08/03/03 05:22

I posted not only to describe the problems I have had, but rather to provide a demo showing them. I am hopeful that a work-around or solution will present itself to minimize the problems.

@fastlane69: Basically all you have done in this entire post is attempt to be annoying and insulting IMHO. If you have nothing to say in regards to the actual topic, why reply at all?

Jason
Posted By: ventilator

Re: ball physics - 08/03/03 05:46

looks like marble madness! [Smile] i also thought about doing a project like this because it could be done very nicely with the physics engine...

do you apply a force or torque to the ball?
did you try to make the level geometry thicker?

code:
         |
| block2
*|
--------++--------
|
block1 |
|

for example block1 should be very thick and block2 should be expanded further down.

* is the ball

...
i noticed the second problem in my experiments too, but it didn't bother me much because if the ground has a grass texture for example, it could be a little stone or something which causes the change of direction! [Wink]
Posted By: Jason Bryant

Re: ball physics - 08/03/03 08:04

This is the player input:

code:
 
// reset the force vector each frame
force.x = 0;
force.y = 0;
force.z = 0;

//allow control of ball if on the ground...
if (ground_dist > 0 && ground_dist < scale_dist)
{
if(key_cuu)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
vec_normalize(force,power); //force vector points from camera to player at length of power
}
if (key_cud)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
vec_inverse(force);
vec_normalize(force,power);
}
if(key_cul)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
force_ang.pan = 90;
vec_rotate(force,force_ang);
vec_normalize(force,power);
}
if(key_cur)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
force_ang.pan = -90;
vec_rotate(force,force_ang);
vec_normalize(force,power);
}
}

and the movement code is:

code:
 
function movePlayer()
{

//increase gravity force if not in a jump...
if (jumping == 0)
{
force.z -=10000;
}

// apply force to player
phent_addcentralforce(player,force);
}

I have tried with thick blocks, but haven't had better success with them. [Frown] Since adjusting the gravity, as I've mentioned before.. the ball going through the blocks is more trivial than it used to be.

I'm not sure how to approach the spinning problem. I would like the ball to continue in an easily forseeable way though. Any ideas as to prevent the odd spin reaction?

thanks,
Jason

edit- I did try using torque at one point to see how well that would work. It didn't work as well as using force. It seemed to pull to the right actually. Marble madness was great! [Smile]
Posted By: ventilator

Re: ball physics - 08/03/03 08:24

it's really strange that the ball begins to spin and penetrate the level geometry that way. maybe you should ask marco about it.

but i am quite sure there are workarounds for this problem. try to play around with ph_setcorrections (try 20000, 0.01 for example) or the parameters (like friction) of the ball. try to avoid that a force gets applied when the ball collides with a wall.
Posted By: fastlane69

Re: ball physics - 08/03/03 08:51

a) Because I can

b) Because I honestly thought you were showcasing your work, not asking any questions.

c) See a)

Harassing and Annoying...that's the polices job, not mine.
Posted By: Jason Bryant

Re: ball physics - 08/03/03 09:13

Here is the player input code.. that includes the jump as well..
code:
 
//----------------------Player Input-------------------------------------
function playerInput()
{
// this function is called every frame from player player action
// reset the force vector each frame
force.x = 0;
force.y = 0;
force.z = 0;

//allow control of ball if on the ground...
if (ground_dist > 0 && ground_dist < scale_dist)
{
if(key_cuu)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
vec_normalize(force,power); //force vector points from camera to player at length of power
}
if (key_cud)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
vec_inverse(force);
vec_normalize(force,power);
}
if(key_cul)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
force_ang.pan = 90;
vec_rotate(force,force_ang);
vec_normalize(force,power);
}
if(key_cur)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
force_ang.pan = -90;
vec_rotate(force,force_ang);
vec_normalize(force,power);
}
}
// add flying force here....
if(mouse_right)
{
//activate current powerup here...
//will use mousewheel to cycle powerups
force.z = glide_power;
//to allow control while flying
if(key_cuu)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
vec_normalize(force,power); //force vector points from camera to player at length of power
}
if (key_cud)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
vec_inverse(force);
vec_normalize(force,power);
}
if(key_cul)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
force_ang.pan = 90;
vec_rotate(force,force_ang);
vec_normalize(force,power);
}
if(key_cur)
{
vec_set(temp.x,camera.x);
temp.z = player.z;
vec_diff(force.x,player.x,temp.x);
force_ang.pan = -90;
vec_rotate(force,force_ang);
vec_normalize(force,power);
}
}

//jumping...
if(mouse_left)
{
// only allow jump if on ground, not in air
if (ground_dist > 0 && ground_dist < scale_dist)
{
jumping = 4;
while(jumping>0)
{
// play jump sound here
snd_play(boing,sound_vol,0);
force.z = jump_power;
jumping-=1;
wait(1);
}
}
}
//force vector now contains player intention forces
}

Jason
Posted By: ventilator

Re: ball physics - 08/03/03 09:39

i think the problem is that the corrections per frame are less than the movement caused by the force applied to your ball. try to reduce the weight of the ball and the forces applied to it! or increase the corrections (ph_setcorrections)... or do both, just experiment with all these values a little...
Posted By: Anonymous

Re: ball physics - 08/03/03 16:58

quote:
Originally posted by fastlane69:
a) Because I can

b) Because I honestly thought you were showcasing your work, not asking any questions.

c) See a)

Harassing and Annoying...that's the polices job, not mine.

Get a life dude, damn....
Posted By: Dan Silverman

Re: ball physics - 08/04/03 07:41

fastlane69,

Let the moderators determine which posts are off topic and which ones are not. Also, there is no need to be insulting in your posts. The better course of action would have been to have said nothing. At least Ventilator was trying to be helpful. You could have done the same.
Posted By: Jason Bryant

Re: ball physics - 08/03/03 20:47

This is the physics setup of the ball. I'm only using a mass of 5. (normal_friction = 50 and normal_damping = 60 currently)

code:
 
phent_settype(my,PH_RIGID,PH_SPHERE);
phent_setgroup(my,2);
phent_setmass(my,5,PH_SPHERE);
phent_setfriction(my,normal_friction);
phent_setelasticity(my,50,40);
phent_setdamping(my,normal_damping,normal_damping);
player=my;

I'm using ph_setcorrections(20000,0.1);

I will set it up so that I can adjust these values on the fly and see if that helps. Thanks for the tips.

Jason
Posted By: fastlane69

Re: ball physics - 08/04/03 05:39

Please see "forum wide apology" on "morbius foreign affairs" for a response to my recent attitudes.

Peace out.
Posted By: ventilator

Re: ball physics - 08/04/03 07:57

i did some experiments and found out that ph_setcorrections(60000,0.01); reduces the problem to a minimum (i only succeeded in penetrating the walls if i really tried hard). you should definitely do some traces and stop applying a force when the ball tries to move against a wall.

and that the ball starts spinning at all is really strange we should ask marco about why this can happen because it's quite unrealistic...
Posted By: ventilator

Re: ball physics - 08/04/03 16:41

marble.zip -> my experiments - you can look into the wdl to see how i did it. i used phent_addtorqueglobal to move the ball because i think it's cooler when the ball slips a little. controls: wasd, right mouse button + scroll wheel to control the camera

are you able to let the sphere fall through the level? i still can do it but only because i know where and how...

it seems to work somewhat better with the current beta because there i could limit the rotation speed. with 6.00.6 i had to disable this part because there is a bug in phent_getvelocity. but even in the beta i can let the sphere fall through the level...
Posted By: seb_dup1

Re: ball physics - 08/04/03 22:33

Ventilator
Under the square pipe , the ball get stuck ..He he
Not enough force?
[Smile]
Posted By: ventilator

Re: ball physics - 08/04/03 23:51

yes, but this isn't the problem... [Smile]

the problem is that if you keep moving against a wall the ball begins to spin and drills through the level geometry.

but in my level it's almost impossible that it happens with the current settings... (it was very tricky to find these settings though!)
Posted By: Jason Bryant

Re: ball physics - 08/05/03 00:55

Nice demo ventilator. I couldn't get the ball to fall through the level after trying for a couple minutes. It is a trivial issue if it takes a lot of work to make it mess up.

I was thinking of trying to use trace as a method to limit the problems I had earlier. I hadn't quite thought of how I wanted to approach it though. I like your movement through torque as well.

I'm not sure of how to limit that odd spin reaction either. Can you think of something that would reduce/eliminate that? Or why that might occur at all?

thanks,
Jason
Posted By: Jason Bryant

Re: ball physics - 08/05/03 23:23

I've gone through your code some more ventilator. It's very insightful.

Removed questions and moved to ask conitec forum.

thanks,
Jason
Posted By: ventilator

Re: ball physics - 08/06/03 13:44

it's just my style. i don't know if it's faster.

code:
vec_set(dir,nullvector);
if(key_a)
{
dir.x-=1;
}
if(key_d)
{
dir.x+=1;
}

the reason i did it this way is that when the user presses a and d at the same time dir.x should be 0. i think it's more elegant than with an additional if statement.

btw. i forgot to time correct the force applied to the ball. the vec_normalize line should be something like that:
vec_normalize(dir,50*time);
Posted By: Jason Bryant

Re: ball physics - 08/06/03 23:00

Seeing your control scheme helped me realize that the way I was doing it was incorrect. I didn't realize I was messing up the actual input in the manner I had it scripted. The method that you have shown is much better. The code is cleaner and logically correct.

I am curious about the speed of some script commands over others. I'll ask the script questions on the ask conitec forum.

Thanks again for your help. It's made it a lot easier for me to realize how much I need to improve my coding techniques.

Jason
Posted By: Anonymous

Re: ball physics - 08/07/03 07:19

Are you referring to the ball falling through the level boundaries (skybox) or through blocks inside the skybox ? I could only reproduce the ball falling through the skybox.
Posted By: Jason Bryant

Re: ball physics - 08/07/03 08:43

I was referring to the ball falling through level blocks, not the sky box. I haven't had any problems since reducing gravity and moving the ball with both torque and forces. However, when I moved the ball with just a force and no torque it would start spinning and go through the level blocks if you applied the constant force on the ball somewhat perpendicular to the level blocks(Or if you were facing a corner).

Jason
Posted By: ventilator

Re: ball physics - 08/07/03 11:37

marco, in my example the problem isn't noticeable anymore with the current erp/cfm settings (although if i really try hard i still can let the ball fall through level geometry).

i first thought jason did apply too high forces but i easily could reproduce it in my levels. if a ball is forced against a wall it starts to spin faster and faster (it doesn't matter if you use a force or a torque to move the ball) and then it moves inside the level geometry.
Posted By: ello

Re: ball physics - 08/07/03 17:48

yes, i recovered the same problem in with my metallballs! they were jumping from wall to wall spinning faster and then dissapearing through the wall [Eek!]
Posted By: old_bill

Re: ball physics - 08/07/03 18:19

I noticed this twice with the old physic beta.
Later with a newer version never again.
Posted By: Anonymous

Re: ball physics - 08/08/03 08:50

The collision detection system checks whether physics objects and wall faces intersect, then applies corrective forces to keep the object on the correct side of the wall.
If the object has a high speed (relative to frame rate and wall thickness) then it could move from one side of the wall to the other side within one frame. To prevent this I trace a line from old position (center of bounding sphere) to new position. If the line intersects a wall, the object gets moved to a place approximately in front of the wall.

These are the three places where something could go wrong: face collision is not registered, line collision is not registered, or corrective forces are not accurate. Since the ERP/CFM settings have had an impact (and they tweak the corrective forces) I am afraid that this is where the problem comes from, which means it will be very difficult to fix.

Is it possible to move the ball automatically through level geometry in a few frames by applying large torque/forces? What are the ERP/CFM settings in order for this to occur? If anyone can achieve this, please send a script/level to mgrubert@conitec.net, so I can step through it and figure out exactly when things go wrong.

Also, there is a level restriction which is not mentioned in the manual, but was discovered by Ventilator:
Physics levels must have an enclosing volume, e.g. a skybox. If this is not present then the physics engine will assume any objects outside your level geometry to be invalid.

Posted By: ventilator

Re: ball physics - 08/08/03 20:07

marble.zip i uploaded my example level with the default erp/cfm settings. just maneuver the ball to a wall and keep moving it into the direction of the wall. first it bounces a few times and then it should fall through the level after a certain amount of spin is reached. the spin doesn't have to be very extreme...

i move the ball by applying a torque but the strange thing is that when the ball moves by applying a central force it starts spinning too and falls through the level when it gets forced against a wall.

setting erp/cfm to 60000/0.01 reduces the problem to a minimum. the disadvantage is that these settings make the ball bounce a little more extreme when it intersects level geometry (overshooting?).

...
a ph command which allows individual entities to override the global erp/cfm settings would be helpful in my opinion. because i wouldn't need 60000/0.01 for every entity in this level.
Posted By: ventilator

Re: ball physics - 08/08/03 20:39

i also sent you an email with an automated example. it's strange because there the problem only happens with the current beta version on my computer. collision in 6.00.6 seems to work much better...
Posted By: Anonymous

Re: ball physics - 08/13/03 04:23

What's happening in this example is that the ball is gaining lots of momentum and is basically "tunneling" its way into the level geometry.
Every frame I check entity/world collisions and set up temporary collision joints to prevent the entity from moving any further. The global ERP/CFM parameters define how restrictive this joint will be. An ERP of 20,000 corresponds to ca. 20% error correction per frame. Thus if the ball is 1 quant into the wall it will be approximately 0.8 quants into the wall afterwards. But since the force is still being applied next time around the ball is 2 quants into the wall, which will be corrected to 1.6 quants, etc. At some point the ball's center is inside the block and there's no hope left.

I mentioned an additional safe-guard before. Every entities center is checked whether it has crossed a wall or not. This, however, only prevents an object from missing a wall entirely. Thus if an object shoots across the room and it would penetrate a wall, A6 puts it roughly in front of the wall and the usual joint mechanism kicks in (not in this case though because the joint is too weak).

Solutions:
- higher ERP value (and lower CFM) to enforce walls more strictly
- phent_setmaxspeed to prevent objects from getting too fast
- larger objects
- more elasticity /more friction / more damping

I will look into setting different ERP values per object or per constraint.
Posted By: ventilator

Re: ball physics - 08/13/03 12:17

thanks for examining this!

wouldn't it be possible to dynamically increase an entity's erp depending on how much it currently penetrates the level geometry?

...
sometimes it's really tricky to find the right combination of parameters. i wonder how they manage to make physics in games like halflife2 foolproof? for example, how do they prevent that a player collects all items of a level with the gravitation gun and throws them onto a pile? all this collisions in the pile really could freeze (<1fps) the game...

marco, have you ever worked with other physics engines like havok?
Posted By: Anonymous

Re: ball physics - 08/14/03 03:49

quote:
Originally posted by ventilator:
wouldn't it be possible to dynamically increase an entity's erp depending on how much it currently penetrates the level geometry?

Well the underlying concept is that ERP allows you to soften constraints by not enforcing them 100%. If you wanted to make sure that the ball does not penetrate geometry, then set ERP to a large value. As mentioned, I will be looking into how feasible it is to use separate ERP/CFM values for different situations (user constraints, contacts).

quote:
sometimes it's really tricky to find the right combination of parameters. i wonder how they manage to make physics in games like halflife2 foolproof?
It's a lot easier if you know what kind of physics simulation to expect, e.g. if Gordon is not going to encounter any beach balls then the constraints can be made stiffer.

quote:
for example, how do they prevent that a player collects all items of a level with the gravitation gun and throws them onto a pile? all this collisions in the pile really could freeze (<1fps) the game...
Well that's something to try out. The other thing would be squeezing matresses and deformable objects through narrow gaps and see if they explode.

quote:
marco, have you ever worked with other physics engines like havok?
I have played with (and broken ;]) a number of physics demos, including Havok 1.0, but not looked at any other proprietary APIs. Last year I was talking to a game developer using MathEngine or Havok and complaining about parameter tweaking- so you are not alone on this.
Posted By: Drew

Re: ball physics - 09/06/03 09:28

ventilator -
Here is some good words from a new guy on the scene "Newton"

"Don't worry my friend...Help is on the way!
There is a new physics engine in development that will blow away anything you have seen before. It is being integrated as we speak...Any version of Gamestudio!...any amount of objects!!... and very little programming.
No esoteric parameters to tune. sounds too good to be true, but I'm using it right now. Its in an early stage, but as an example:
- A5 commercial dropping MANY objects into a scene with EXCELLENT realistic behavior.

COMING SOON!!!
Posted By: ventilator

Re: ball physics - 09/06/03 13:31

yes, it really sounds too good to be true!

is this programmer a colleague of you? what physics engine is it based on? or did he do this from scratch? what is his motivation for doing this?
Posted By: EKA

Re: ball physics - 09/06/03 16:52

Hey Ventilator,

I've been testing Newton Physics as well. It's damn cool. He is a friend of Dr. Jelly and myself. He made it from scratch a while back ago. We showed him Gamestudio and he wanted to see if it could be ported to it. It took him a day to do it. He is motivated by the fact that there isn't a good physics solution available for the Gamestudio masses and he's having fun doing it.

Eka
Posted By: Drew

Re: ball physics - 09/06/03 17:28

exactly.
He's just doing it for fun... he gets VERY excited when we brainstorm different physics functions...

actually right now we are checking out the legal issues of a public release... maybe just some demos...maybe the release, its up to Newton and what he wants to do.
I'm just the messenger until he registers...
Posted By: ventilator

Re: ball physics - 09/07/03 01:57

please tell us some more about the features of this physics engine!

does stacking boxes work well? does it support constraints? will things like a car setup be possible? ...
Posted By: EKA

Re: ball physics - 09/07/03 11:17

yes, yes, and yes, once things are integrated into Gamestudio. They physics engine by itself has all those features. A lot of it is still being integrated into GS.

Eka
Posted By: ventilator

Re: ball physics - 09/07/03 11:51

and what are the legal issues? is this engine also in use by shiny?
Posted By: EKA

Re: ball physics - 09/08/03 03:01

No it's not using Shiny's. That is not the issue. We'll know more next week.

Eka
Posted By: BHoltzman

Re: ball physics - 09/13/03 16:13

I downloaded the marble demo you made and played around with it. It's fun to move the marble around.

I was able to get the marble to fall through the floor by changing the direction of the camera and then running the sphere into a wall with the camera angled ~80 degrees from looking straight at the wall.

I'll try to repeate it to make sure it's reproducable.

EDIT: Yep. It fell through the floor again. Maybe a problem with the physics system?
Posted By: Drew

Re: ball physics - 09/19/03 08:13

I'm not able to download your marble demo...
Doesn't seem to be there...

Thanks
Posted By: EKA

Newton Demo Released - 09/25/03 13:41

Newton Demo Released

look in User Contribution.

Eka
© 2024 lite-C Forums