x


Component organization for shooting

I have some troubles with shooting, so just checking if I am doing this right.

So player with controller should be attached shooting script that shoots and has lines to apply damage to hit objects. All the objects (enemies) have a script that sets their life and kind of a receiver that checks if damage is sent from shooting script and it applies damage then.

Or there are other ways to do this?

Thanks

more ▼

asked Feb 24 '10 at 03:41 PM

Dima Antonov gravatar image

Dima Antonov
64 6 7 15

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

That is a good way to do it; the shooter sends out a raycast, and sends a message to whatever it hits which calls a function to apply damage (the enemy has a function to apply damage, which is called by the shooting script when it hits).

more ▼

answered Feb 25 '10 at 01:19 AM

Jason_DB gravatar image

Jason_DB
1.9k 4 14 36

Great to know I've done it right. I fixed my scripts and they work like they should now. I have 2 correct answers to the question. But I marked 2nd as a true, just because I learned some important stuff there. Thank you, I'm happy to know I've done it right.

Feb 25 '10 at 06:52 AM Dima Antonov
(comments are locked)
10|3000 characters needed characters left

you can do this in many ways. you should create a shoot script for the player. for damage you can create a damage script for your bullet or attach the code to shoot script or create a damage script for enemies. having a damage script for bullets is the best approach because you can customize it for different bullets to have different types and amounts of damages. in your bullet you should check if you collide with the enemy or even you can check this in enemy. for example you can tag all of your bullet types with bullet tag and in Trigger functions of enemy check if the other collider has the bullet tag then get the others damage component and execute it's apply damage function. you can do these things in many ways. it's dependent to your project.

more ▼

answered Feb 25 '10 at 05:18 AM

Ashkan_gc gravatar image

Ashkan_gc
9.1k 33 56 117

Yes, I think if I decide to implement more weapons in future, this info is what I need. I like to know general concepts first. Thanks a lot, I fixed my shoot and damage scripts, now all working sweet.

Feb 25 '10 at 06:55 AM Dima Antonov
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x275

asked: Feb 24 '10 at 03:41 PM

Seen: 1194 times

Last Updated: Feb 24 '10 at 03:41 PM