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 / [Dark Physics] ray casting for my guns

Author
Message
FINN MAN
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 1st Sep 2006 22:34
Can any one show me some code of how to use ray casting for a bullet system? I don't have a clue of how to do this, I want to use the ray casting to detect if a object was hit and then apply some forces to the object at the position of the bullet's impact.

FINN MAN
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 2nd Sep 2006 04:59
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 2nd Sep 2006 07:23
You don't need to ray cast for that.

Check the collision of the bullet and apply forces to the object it hits.

if phy get collision data()
a = phy get collision object a()
b = phy get collision object b()
if a or b then .....

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 2nd Sep 2006 07:38
Bullet objects shouldn't be used for bullets because they move too fast to accurately register collision and forces. Raycasting is certainly the way to go.

Here's another consideration - if you are raycasting with Dark Physics, then you are raycasting to other physics bodies. If you are raycasting to a static mesh, that's fine. However, if you are raycasting to a character controller, then there is no way that you can get accurate collision data.

I use Sparky's DLL in conjunction with Dark Physics. His raycasting is simple, fast, and perfect. I can shoot a character in the arm, rather than shooting at his controller capsule. For this reason, I'm not even going to waste my time with the Dark Physics raycasting.

Something to consider.


Come see the WIP!
FINN MAN
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 2nd Sep 2006 22:10
Cash thanks I did not think about that.

Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 3rd Sep 2006 02:12
Cash is right. Most games should make use of ray casting for bullets instead of objects. However, you can use objects if you take the tracer fire approach. Instead of having a small bullet object, you have a long thin plain (or cylinder) with a length as long as the distance it travels per loop (or slightly larger). This requires a minimum loops per second to work properly though. You can texture it so it's bright red/yellow at the front, and fades out at the back for a nice effect. This ensures your object is sufficiently large to always collide with the scenery, and also you get to see a cool tracer fire effect.

It's more suitable for arcade games than real games though, as it's a bit unrealistic to have 600 rounds per minutes of bright yellow tracer fire in a realistic FPS. It's also more strain on the CPU and GPU. If you still want the accurate ray casting collision, you'll have to cast a ray from the bullets old position to its new position each loop and handle collision manually. I mean, there're loads of methods really to get the exact effect you want, but if you just want realistic, almost instant bullet travel, stick with the ray casting approach.


Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 3rd Sep 2006 03:11
phy set continuous cd 1.0
phy set rigid body ccd bulletID, 1


Quote: "Continuous collision detection is useful for fast moving objects. With traditional collision detection fast moving objects can pass through other objects during a single time step. This effect is known as tunneling. Imagine a bullet traveling towards a thin metal plate, in the first time step it would be on one side and in the next it would be on the other. Dark Physics would never detect a collision and hence not constrain the motion of the bullet.

To deal with this problem a technique known as continuous collision detection (CCD) is necessary, instead of testing for collision at discrete points it tests an extruded volume which represents the objects motion during the whole time step. If a collision is detected, the time of impact can be computed and the objects motion constrained appropriately.
"


System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
FINN MAN
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 3rd Sep 2006 04:36
can some one give me some code? Not sure how to do this.

Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 3rd Sep 2006 05:17
Even if the precision of that method is adequate to register the collisions necessary for bullet collisions, it's still going to be much more processor intensive than raycasting. Coupled with the fact that the end result would be the same, there's no point in using this method for bullets.

There are plenty of other applications that could utilize CCD, so it's great that they included it. I just don't think that bullets are the ideal use.


Come see the WIP!
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 3rd Sep 2006 06:45
Cash Curtis II

If you are using lasers that is true but if you are using physics the bullet can be altered by gravity and also you could try a ricochet shot.
I cut down on the computational intensity by rotating thru abou 100 bullets

The only snag at the moment is i cannot get the command
phy set rigid body ccd bulletID, 1 to work. As soon as I can which might require the next upgrade I will publish an example

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
imekon
17
Years of Service
User Offline
Joined: 3rd Jul 2006
Location:
Posted: 3rd Sep 2006 10:24
Quote: "phy set rigid body ccd bulletID, 1"


This always gives me a runtime error, making it useless.

"Reality Bites"
bosskeith
18
Years of Service
User Offline
Joined: 5th Dec 2005
Location:
Posted: 3rd Sep 2006 11:13 Edited at: 3rd Sep 2006 11:15
actualy codger what cash curtis means is to use the old position of bullet and new position of the bullet for the endpoints to test the collision...not from character to the bullet. therefore the loss of accuracy in the gravitational arc will be minimal because it is still the exact path the bullet actualy takes each frame.

Ink all over the screen...and dang it! Signature still does not show.
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 3rd Sep 2006 12:10 Edited at: 3rd Sep 2006 12:11
There are so many possibilities. If you want a ricochet, you can get the bounce vector from the collision and calculate that as a separate bullet collision. Since a real ricochet happens almost instantly, this would be fine. The range of the ricochet can be a function of the distance of the initial collision and the material struck. Not only would it be accurate, but it would be computationally nominal.

Anything larger, like a grenade, I would of course use a real physics body launched from the player's weapon. For bullets, though, I'd 100% go with raycasting.


Come see the WIP!
FINN MAN
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 3rd Sep 2006 21:21
Can any one give me some code for ray casting for my guns?

FINN MAN
19
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 4th Sep 2006 05:23
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 4th Sep 2006 08:25
Do you have Sparky's collision Dll v2?


Come see the WIP!
Bluedemon
17
Years of Service
User Offline
Joined: 2nd Sep 2006
Location: USA
Posted: 8th Sep 2006 01:16
I don't understand how two different physics engines can work together like that. Wouldn't one have to setup collision on everything for both engines. Maybe you can demonstrate?
Lani
17
Years of Service
User Offline
Joined: 14th Aug 2006
Location:
Posted: 13th Sep 2006 12:26
Slightly off-topic, but not too much: I get PC freezes whenever I introduce any of Sparky´s DLL commands (ie the SC_ ones) into my DP project. I used Sparky´s for the first version of it (before introducing DP) where they worked fine. Which is pretty strange if you ask me!
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 14th Sep 2006 06:30
@Bluedemon-
Sparky's collision DLL has nothing to do with physics, it's just collision. You do have to set up the models for collision, but the overhead is nominal and the results are great. No matter how well the Dark Physics raycasting commands work, they will only ever be able to cast to physics bodies, rendering them useless against animated models.

@Lani-
You're probably missing a memblock command somewhere in your code. Without a memblock command, the memblock DLL is not loaded and the program will fail. Look through the examples and you'll see what I'm talking about.


Come see the WIP!
Lani
17
Years of Service
User Offline
Joined: 14th Aug 2006
Location:
Posted: 14th Sep 2006 10:16 Edited at: 14th Sep 2006 10:17
Ah, right you are CC. Since I dropped Advanced Terrain (and some other changes) I had no memblock commands at all. I added a bogus memblock command at the start of the program, and now the SC_ commands are working - excellent, thanks
CTF Freak
18
Years of Service
User Offline
Joined: 27th Oct 2005
Location: In your base
Posted: 27th Sep 2006 05:50
Quote: "No matter how well the Dark Physics raycasting commands work, they will only ever be able to cast to physics bodies, rendering them useless against animated models."


Does sparky's dll work on animated models? I never could get it to work with them. If it does can you show me how?
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 27th Sep 2006 09:36
It sure does. You probably aren't using "SC_update obj" (in a for...next loop to include all of the collision bodies) each loop.


Come see the WIP!

Login to post a reply

Server time is: 2024-04-16 14:11:24
Your offset time is: 2024-04-16 14:11:24