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 GDK / [3D] Best way to shoot?

Author
Message
jCedborger
14
Years of Service
User Offline
Joined: 21st Jan 2010
Location:
Posted: 4th Feb 2010 09:21
Hi, I'm working at a 3rd person shooter game.
I've searched around for a function to make the character shoot, but I can't really find what I'm looking for.

What is the best way to make a character shoot? I've tried to set up a small sphere and make it "shoot away" when I click my mouse, bot when I release the mouse button, it just comes right back.

I want the mouseclick to function as a trigger:

1. You aim
2. you click the mouse and the "bullet"/sphere shoots away towards the crosshair(a sprite positioned in the center of screen).
3. if you HOLD the mousbutton down, it just keep spraying spheres.

What is the best way to do this? should I even use spheres or will this use unnecessary performance?
bloodmage2
15
Years of Service
User Offline
Joined: 14th Jun 2009
Location:
Posted: 4th Feb 2010 17:57
have a function that runs constantly to keep moving the spheres, regardless of the mouse. have a second function that checks for mouse clicks, and then loads and places the model/creates the primitive.

-to the optimist, the glass is half full. to the pessimist, it is half empty, to the engineer, it is twice as big as it needs to be.
jCedborger
14
Years of Service
User Offline
Joined: 21st Jan 2010
Location:
Posted: 4th Feb 2010 21:19
So to create spheres for every bullet is the best way? And requires least performance?

The function will work like this:
1. check if you got ammo left, if it is not- nothing happens.
2. If there is ammo left, check if singleshot/bust or automatic mode
3. Find the crosshairs position and fire towards it and ammo decreases.
4. If bullet hit another characrers collisionbox, that characrers life decreases and sphere deleted.
5. Else if it missed, on collision with any other object than character, delete bullet.

Thats pretty much it for the fire function right? Or am i missing somthing?
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 4th Feb 2010 23:46
I would have a sphere always at the players position with the same rotation. Then when the player click's, I'd move the sphere then do a raycast between the sphere and player's position.
jfroco
14
Years of Service
User Offline
Joined: 1st Dec 2009
Location: Chile
Posted: 5th Feb 2010 03:09
Hello jCedborger,

Personally I wouldn't use an object as bullet normally. Unless I was using it for some physics-based engine.

I think the most simple way of do it is to point with the crosshair using "pick object" function and then when the player fires simulate the shot with a sound or some light but not an actual bullet.

I wrote this code that I think does what you described. Move player with left and right arrow, fire with left button.




I hope this helps.

Login to post a reply

Server time is: 2024-10-01 23:36:32
Your offset time is: 2024-10-01 23:36:32