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.

Dark Physics & Dark A.I. & Dark Dynamix / How to find out collision impact speed?

Author
Message
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 5th Apr 2009 01:23
I'm trying to discover a way of finding out if two objects have collided, and if one of the objects was traveling over a certain speed when the collision occurs, then I want to play a sound effect.

Currently, I've got this code:

So that kind of works. If the playerBallObj is traveling at less than -150, or more than +150 when it collides with something, it plays the sound effect. Great.

However, if the ball is rolling along a surface and goes over that speed, then the sound is also played. That's not what I want. I just want to play the effect if the ball is moving at the appropriate speed, when it initially collides.

I've had a little monkey with PHY GET COLLISION NORMAL FORCE X, but it expects two integer values, and the help files don't tell me what they should be. I've tried feeding in PHY GET COLLISION OBJECT A and PHY GET COLLISION OBJECT B as the two values, but I always get 0 returned.

Because collision data is always being generated when the ball rolls along a surface, I'm not sure how to separate out the initial strikes of the ball.
Orion1024
15
Years of Service
User Offline
Joined: 7th Mar 2009
Location: Dimensional Coordinates: 323.935.914.157
Posted: 5th Apr 2009 11:20
Keep in mind that Dark Physics puts collision data on a stack, so you're supposed to empty the stack completely every program cycle. This is the recommended usage in the help file:



As you mentioned, there could be a lot of unnecessary collision data to retrieve due to collisions between the ball and ground (if all you want to test for is collision between a ball and another ball, etc). Honestly, I think it's easier to use Sparky's DLL for collison in conjunction with the phy get linear velocity, etc. That's what I did, anyway.

Looking for the vortex to another Earth
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 5th Apr 2009 13:20
give this line ago, might do what you want, I found that the data tends to swap around.



Dark Physics makes any hot drink go cold.
Duke E
15
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 6th Apr 2009 04:34
The collision data only is pretty useless in these situations as the physics makes the ball jitter up and down over the surface. I use a raycast in a similar case as i need more than check a single plane. If you only have a flat surface you can just check the height of the ball off the surface.

Raycast from the ball a couple of units down, if the ray hits something you know you are close to the ground and set a variable for this, closetoground=true.
Then when you hit with collision data, play the sound and set another variable to hitground=true. If both are true, don't play any more sounds. When ball leaves ground by bouncing, rolling off a ledge or something (detected by the raycast) you set closetoground=false and hitground=false.

The drawback is the raycasting in dark physics isn't 100 percent.
I do the same as Orion1024, use Sparky's.

Regards
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 6th Apr 2009 10:45
That doesn't help I'm afraid. If I was missing collisions, then I can see how checking for either a or b would help.

Here's a quick diagram of what I want:


The first picture is working correctly. As the ball is traveling over a certain speed, each time it bounces (the black 'sparks') it plays the Dink effect.

The second picture is how it's currently working. As the ball rolls down a slope, because the speed is picking up as the ball rolls, it plays the Dink effect constantly.

The third pic is how it should work. As it rolls down, no effect is played, and then when it hits the other line, the Dink effect should be played.

That's why I need to be able to get the force of the collision. I suspect Sparkys would suffer the same problem (unless that allows me to find out the force of a collision).

Unfortunately the maze is a 360 rotating one, so it's possible to hit 'the ground' from both sides. This means I would need to raycast in all directions, all the time.
Duke E
15
Years of Service
User Offline
Joined: 10th Mar 2009
Location:
Posted: 6th Apr 2009 12:12
Try a combination with torque detection maybe?

As the ball should be changing it's rotation very much when it hits something, the rotation changes should be low and pretty linear when it's rolling and accelerating.
But when it hits something the rotation should change profusely.

Just a teory, have'nt used the angular momentum or torque commands much, just to limit rotation.

Regards
Orion1024
15
Years of Service
User Offline
Joined: 7th Mar 2009
Location: Dimensional Coordinates: 323.935.914.157
Posted: 6th Apr 2009 14:03
It looks like the first parameter of the 'phy get collision normal force' command should be the ball object number and the second parameter needs to be zero. Here's an example I put together...



I've made the x_force, y_force & z_force variables global so you can see their values. You'll need to adjust the 'COLLISION_THRESHOLD' constant depending on the global gravity, object mass and it's maximum velocity.

Looking for the vortex to another Earth
tiresius
21
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 7th Apr 2009 00:15
First off, I use Newton. But I just thought out how to do this myself so I thought I'd share. If Orion1024's suggestion doesn't work give this a shot.

First you keep track of the player's last velocity vector. Then you subtract it from the player's current velocity vector. If the result of the vector distance is great enough, it is most likely that the player hit something at a good enough speed. I plan on increasing the volume of the hit sound based on the speed of impact.

I'm not a real programmer but I play one with DBPro!
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 7th Apr 2009 12:35
Thanks a lot guys. I'll try out the code this evening.

Login to post a reply

Server time is: 2024-05-02 12:52:47
Your offset time is: 2024-05-02 12:52:47