Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
armin-nimra

how to make damage Indicator

Question

hi,I wanted to know that how can I create an damage Indicator in Unity 3D ?
I went very search, but I did not find anything!
If the code is so much better.

Share this post


Link to post
Share on other sites

26 answers to this question

Recommended Posts

  • 0
Posted (edited)
Please login or register to see this quote. Please login or register to see this code.

Hope thats enough to get you started and understand it... 

with this you should be able to do something like what you can see in cod.

 

Edited by Erarnitox
format the code too make readable
  • Like 2

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

hi,Can you add complete the script??

how to send direction damage to this??can i use ui image instead of texture?

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

1) just pass it as an argument to the method.

2) sure can but im still kinda stuck the the old GUI system just used to it 

3) for me to post a complete script i would have to know your project / what your damge script looks like  

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

yeah, you can call the method like that, just pass in this.transform.position as an additional argument, so you can reference it. 

like:

hit.gameObject.SendMessage("ApplyDamage", DamageValue, this.transform.position, SendMessageOptions.DontRequireReceiver);

(if you do singleplayer stuff and only want to damge the player i would suggest to call it by accessing the Component diectly tho.

So if you hit the tag player just playerDamageController.ApplyDamage(5, transform.position)) 

 

than on the gameObject that was hit you have to have a Component that implements ApplyDamage(int DamageValue, Vector3 DamagePosition) so something like this: 

 

public void ApplyDamage(int DamageValue, Vector3 Damageposition){

      this.indicatorTime = 2f

      //calculate Angle 

      this.adjustAngle = calculatedValue

      //apply damage stuff:

      this.health -= DamageValue

 

hope this helps ... i think this is simular to how it was manages in the fps-kit? If you use the fps-kit give me some time i was thinking about extending the fps kit once i find time to do it. 

I love OMAs work and it was a great learning resource for me as well but i think hes not interested in developing this further. 

So if i find the time i might ask him if i can extend it as kind of my way to give back to this community. 

 

Edited by Erarnitox
  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

tbh. this looks right to me. Might be i overlooked sth. tho. does your Damage Indecator texture point upwards?  maybe try to call it from a debug script to test various positions? also try to set adjust manually to see if it starts out at the right position and rotates the way you expect. ... the update position method itself looks from what i see like it should (might have overlooked sth.) 

 

Share this post


Link to post
Share on other sites
  • 0

ys damage indicator texture  point upwards i really cannot figure how t ocall it  for a debug script to test position...

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

i tested increasig the alpha value tto show the indicator from the start and with values you can sse in the video i got that

 

 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote. Please login or register to see this code.

i just flipped the left/right code part .... 

maybe that works ... 

from your video it looks like it might. 

Just a guess but maybe you somewhere flipped the argument and thus the plane the 2 vectors span is upside down. 

I will check that later if it works to fix that properly ^^ 

 

but use this script first to see if it fixes the problem 

Share this post


Link to post
Share on other sites
  • 0

i tired everything but sincerly cannot figure how t omake indicator to show correct damage position...i think i'm goging to purchase a premade asset from the store

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

give me one second ill check something :)

 

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

well i did some cleaning up to undestand the code better but i hnestly think everything should be fine with your code! 

i made some small simplifications, maybe give it a try? But it should do the same thing....

also im pretty positive the code should work! I went trough it step by step all the calculations should be right :o 

Still here is my version of the script: 

Please login or register to see this code.

You could check if the Main Camera is really the only active camera in the scene 

Also you could check with a static position like a cube if the indicator alsways points to it 

(maybe there is a problem with the bullet/ turret position) 

 

well good luck with it and hopefully i solved it by accident haha ^^ 

 

Edit: wait... i messed sth. up was testing it ^^ haha 

Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0

hi and thanks for your effprt and for your new code.. it's seems to work a little better than mine but not good at all.. btw you gave me an hint.. main camera is not the only on the scen of player since it has a weapon camera too.. could this will be a problem'

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

if its facing a different direction but i think this is unlikely 

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

made some small changes again and now its working fine for me :)

depending on your texture you might want to change the offset variable to something else like Screen.height/4 instead of /2 but that does look better for me 😛 

i saw u used /4 in your code thats why i did mention that 😛 so anyways here is the code: 

Please login or register to see this code.

I did also write a small script to test it: 

 

Please login or register to see this code.

the second script is only for debugging but it helped me to figure out the offset that looks right. 

 

here a clip of it in action: 

 

 

Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0

thanks mate but it's all messed the same

i test even with you gently provided scrpt and create  cube and assigne the player as script and target and this is the result

 

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

thats strange tbh. 😕

does it get called from somewhre else as well maybe? 

i really dont know at this point but it pretty confident that the code is okay 

 

edit: this is a pretty dumb idea but .... maybe disable the minimap? 

 

edit2: most likely its not the minimap but probably sth. real simple... try to disable as much from the scene as possible to make a "clean" environment for testing... maybe you stumble over the thing that causes it? 

 

Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

okay... well i dont think it will change much but here are some last simplifications to slim down room for error: 

 

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

nope...all messed up ..i think there is something strange here... bout yur suggestion to remove radar . simply disabled radar gameobject to test.. right?

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

yeah, but i dont think that was the problem ... but i have no idea what might be 

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...