T
T
trzp2020-12-15 12:52:27
Unity
trzp, 2020-12-15 12:52:27

Hello, I need a script for a bullet from a weapon so that it deals damage to another character, how can this be implemented?

The character has a weapon, it shoots beautifully, I can’t understand how you can make a script for the bullet so that the bullet does damage?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
KoreanGuy, 2020-12-15
@KoreanGuy

The bullet doesn't do damage, it usually doesn't exist at all. There is a system that checks if the player hit someone or not, then, if they hit, it transfers data to the second system, which monitors the state of the npc. You can, of course, make a bullet that will really collide with the npc, but why, if it is still not visible? Create hundreds of short-lived objects that require physical calculation. engine - such an idea. Moreover, the flash from the shot and the recoil mask the absence of a bullet even more.

V
Vasily Bannikov, 2020-12-15
@vabka

If you have such a case that the projectile should be visible, then check the moment the projectile intersects with the character and inflict damage on its HP component.
It won’t be more specific, because no one knows how your system with hp and weapons / shells is made.
For the projectile, apparently, it is necessary to have some kind of component / system that will be responsible for causing damage.
I would call it Projectile and check for collisions of all Projectiles with characters - if there is a collision, then destroy the projectile (if it should not fly through) and check if the object with which the collision occurred has a component with hp - if so, then we do damage.

W
WebDev, 2017-01-12
@DarCKoder

Add a flag that the slider is moving at this moment, and prohibit clicking on the button until the animation ends

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question