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.

Newcomers DBPro Corner / Bullet collision.. Easy? Or not?

Author
Message
JJJ0han
16
Years of Service
User Offline
Joined: 4th Oct 2007
Location: Brisbane, Australia
Posted: 9th Nov 2007 11:14
I've been using visible bullets for a while, they work well, but now I want to start on the collision with them.

Just a quick question.

I'm trying to make the bullet check if it collides, for example, if it collides with an enemy, I want it to kill or hurt that enemy.

If It collides with a wall, I would just want it to make an impact sound and if possible add some bullet holes.

Basically I want to allow for different kind of collisions, and if there's a way of finding out what object it has hit, especially an object in an array so I don't have to check every single enemy that I create.

I thought it was going to be easy until I found out that the following code would only check in a straight line:


It probably IS easy, but I'm not getting any wiser at the moment.
How would I make it trace in the direction the bullet is going, instead of a definite angle straight ahead.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 9th Nov 2007 11:45
SC_rayCast(0,X#,Y#,Z#,X#+bulletxvelocity#,Y#+bullityvelocity#,Z#+bullitzvelocity#,2)

If you don't know the velocities of the bullit and are using move object then you can get the velocities with basic trig, vector commands or moving the bullit and getting its new co-ords then moving the bullit back to its old position. With the last option you don't need the velocities as you have acquired the actual destination data.
I'm not sure of the fastest method, but they'll all get the info you want.


The word "Gullible" cannot be found in any English Dictionary.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 24th Nov 2007 18:34
another way would to be to store the bullets coordinates before moving it, then move it then you could use


as for detecting what was actually shot, you should group the objects accordingly (ex: group 1=level objects, 2=enemies etc...), then you can run multiple raycasts for each object group ex:


the first raycast isn't really necessary, but will prevent performing multiple raycasts when no object has been hit. I have changed the exclude object parameter to 0 assuming that your object number 2 Isn't a part of either group.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 3rd Dec 2007 04:31
Why use a ray cast? Just use standard collision, DBPro's native collision can return the number of the object the bullet hits.


"Ok, so that wasn't funny. I don' have any good Christmas jokes."
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 3rd Dec 2007 05:44
Because raycasting is faster, easier, and returns a lot of important information (like the angle of the polygon hit, allowing you to place a bullet decal down).

Raycasting > Automatic Collision * 1000000

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 3rd Dec 2007 05:54
Hehe. Ok, I'll keep that in mind next time I code bullets.


"Ok, so that wasn't funny. I don' have any good Christmas jokes."
Rain Man
16
Years of Service
User Offline
Joined: 19th Nov 2007
Location:
Posted: 3rd Dec 2007 06:26
Quote: "Why use a ray cast? Just use standard collision, DBPro's native collision can return the number of the object the bullet hits."


Another problem with using collision instead of ray-casting is that it's quite possible for the bullet to be completely on the near side of the wall in one program cycle and then be completely on the far side of the wall the next. In this case, no collision will occur.

Ten minutes to Wapner.
Shell Shock
16
Years of Service
User Offline
Joined: 4th Dec 2007
Location:
Posted: 5th Dec 2007 04:59
I'm not familiar with DBP, so my suggestion probably isn't that valid, but what about using a detection line or cone, and then placing the decals and damage down based on that?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 20th Dec 2007 18:57
detection line? Ray Cast is a Line? From a Programmer's Ray Gun... isn't it?

Shell Shock
16
Years of Service
User Offline
Joined: 4th Dec 2007
Location:
Posted: 22nd Dec 2007 08:40
I'm just saying, I'm not sure how you would code it, but have a cone 'cast' from the front of the weapon (to simulate spread) and then place a collision and decal randomly somewhere inside that cone.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 22nd Dec 2007 17:39
How about a invisible sphere positioned kinda far (Past the wall) and then take the sphere coord's - and randomly raycast to one of the VERTEX x,y,z + Positions in the sphere mesh - Then you'll get a circular spread.... to randomly "Choose" from.

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 24th Dec 2007 04:05
Yes, those methods would work, but they're just simulating what raycasting can do, except slower and less efficient, and still not providing near as much information as rays can. Sparky's dll allows you to add "thickness" to your rays even, for things like shotguns or beams.

A lot of people tend to think ray casting is only good for fast moving projectiles that you dont see, but thats not the case. Lets say you have a rocket being shot from a rocket launcher at a wall. The problem stated a few posts above is true, there is a chance that if you just use object collision, the rocket could be (and probably would be) at one side of the wall in one cycle, and then the other side in the next. In fact the chances of the rocket landing on a position inside the wall are really small. So, you use ray casting. Get the rocket's old coordinates before it moves forward, then move the rocket forward, and now get it's new coordinates. Project a ray from the old to the new coordinates, and you'll be able to detect a collision. Using sparky's dll you still have access to the position and angle of the polygon hit, allowing you to place down a big blast decal, an explosion animation, and more.

Ill say it again, raycasting > built in collision * 100000 .

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Dec 2007 04:19
My Method - the sphere thing - IS a ray casting technique - just my idea was to get a circle spread from random vertex off a Circle

I agree 100 that ray casting is not only "full of info" once you learn how to ask Sparky's what happened (like where did it hit, etc) but its just fast.

Raycasting for Projectiles? Good Idea. Sparky Collision for other stuff ... Good Idea. DBPro built In collision? Stop Now while you still can! (It works - just much slower - and some say not as good - various reasons)

Sparky's DLL has a proven track record.

Login to post a reply

Server time is: 2024-09-27 08:26:38
Your offset time is: 2024-09-27 08:26:38