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 object

Author
Message
Derekioh
15
Years of Service
User Offline
Joined: 1st Feb 2009
Location:
Posted: 10th Sep 2009 19:19
Hey, i'm working on a FPS and i was wondering how you would make an object that would shoot and hit an enemy and then return to the same position before you shot the bullet.

thx in advance
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Sep 2009 20:59
Don't use objects for bullets. The reason is that you're going to need them to move really fast, and to do that, they have to basically 'skip' positions. The faster they move, the less chance they have of actually intersecting your enemy, even if you shoot right at it.

To tackle this, use raycasting, using Sparky's Collision DLL, or the slower built in 'Intersect Object' command.

"everyone forgets a semi-colon sometimes." - Phaelax
Derekioh
15
Years of Service
User Offline
Joined: 1st Feb 2009
Location:
Posted: 11th Sep 2009 19:20
ok, i have sparky but i never thought to use raycasting (since i've only programmed for like a year). By the way, if you use intersect object or raycasting, how would u slow the firing rate (EX: i have a shotgun and its just keeps shooting and i want it to shoot 1 shot per second).

Thx
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 12th Sep 2009 06:17 Edited at: 12th Sep 2009 06:24
I think you would do something like this:



Here is a small demo, check it out:



I'm newer to programming than you are, butI think that should do the trick.

ßõw§€r¥¤
z_man
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: Australia
Posted: 12th Sep 2009 07:22 Edited at: 19th Sep 2009 03:17
If you have sparky's, you can use something like so:



This code is partially untested (modified from a project of mine). Hope it helps!

EDIT: Sorry, I should explain how it works. First, the camera position is stored in the x1#, y1# and z1# variables. Then the camera is moved far into the distance (as if it were the bullet). The new position is recorded in the x2#, y2# and z2# variables. The camera is then put back to where it started. Now we have two coordinates - both of these can be used to cast a ray and return any collisions along the way. The For...Next loop goes through each collision and returns the object. Other commands in sparky's DLL can be used to get other useful information (such as normals, etc).

If you're having troubles with all this, I'll try to explain further - it can be hard to grasp at first.

chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Sep 2009 01:38
hallo friends

Of course we can use raycasting using Sparky's Collision DLL, or the 'Intersect Object' command as Zotoaster says, but what about if we are so romantic that we want to use the old way of an object flying straight ahead ?

Here I have a piece of code I hope it can help some one...




oh my god
Derekioh
15
Years of Service
User Offline
Joined: 1st Feb 2009
Location:
Posted: 14th Sep 2009 18:19
thx, i'll test out this stuff today and i'll see if i need any more help.

thx again
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 16th Sep 2009 22:55 Edited at: 16th Sep 2009 23:02
@ Z_Man, what is the "ObjT" for?

When I run your code as-is it gives me an error saying ObjT does not exist.

Are the x2,y2,z2 suppose to equal "camera position x" not object position x?

When I change it to:



It returns a number like 700000000 and the number just stays it doesn't revert back to 0. Help?

ßõw§€r¥¤
Kira Vakaan
15
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 17th Sep 2009 22:10
chafari: Yes, we could do that, but as Zotoaster pointed out, that method has some pretty problematic consequences. In your example it works fine, because the thing you're shooting at is longer than the speed of the bullet, and so it's impossible for the bullet to "skip over" the sphere, but the bullet in your example is a little slow for something you'd actually use in an FPS. Try changing the speed of the bullet to 150.

Of course, you could be completely aware of this issue and I'm just preaching to the choir, in which case, I apologize.
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 18th Sep 2009 16:12
I think I figured it out. Tell me if this is right? It seems to work in that demo, but when I try to transfer the code to my other project it doesn't work so well (only returns a really big number starting with 7).



ßõw§€r¥¤
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 18th Sep 2009 21:57
You are right Kira Vacaan but actually when we shoot, the bullet doesn`t hit immediately,unless we a so close to it, as it takes some milliseconds of second to reach the end of its power.When we do it by the method of intersect object,Sometimes, hit several objects at the same time and we have to write conditions to avoid to kill more than one enemy at a time.
About speed of the bullet, ha ha...you check this handicap...that is truth..., just to give a chance to the enemies to scape.
I use differents methods .As z_man pointed out we can use the camera position and move it hundreds of units ahead to get all coordinates x,y,z new_x,new_y,new_z and finally use an intersect object to use as the bulles.

Here is another example.



oh my god
z_man
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: Australia
Posted: 19th Sep 2009 03:17 Edited at: 19th Sep 2009 03:19
Quote: "@ Z_Man, what is the "ObjT" for?"


Wow, sorry about that, my mistake. You can just get rid of objT and leave empty brackets. In my project I was actually using objects to mark the two raycasting points.

EDIT: I've modified the code I posted above - hopefully it will work now.

Login to post a reply

Server time is: 2024-11-24 01:41:51
Your offset time is: 2024-11-24 01:41:51