#Akizuki

1 messages · Page 1 of 1 (latest)

woeful bridge
#

asdf

#

so aye

#

"so I'd recommend that in the enemy's script, you have say public void TakeDamage(int Damage){ BLAH BLAH BLAH }"

viral walrus
#

yeah i have something similar one moment

#

the second one is the bullets script

#

the oncollisionenter2d void works how i want it to... the ontriggerenter2d one doesnt

woeful bridge
#

back

#

sorry about that, just checking up on the dogs

#

ah so

#

just quickly looking at that, trigger is a different thing from collisions

#

there's just some checkbox for it in the inspector on the object

#

it's a bit messy

viral walrus
#

np man... honestly still really stuck... ive tried putting the script under ontriggerenter 2d under oncollisionenter2d instead but then it says that getcomponent doesnt exist...

viral walrus
#

if this works imma be very happy

#

it.... did not

woeful bridge
#

try collision.collider.getcomponent etc.

viral walrus
#

i tried ticking "is trigger" under the 2boxcollider on the inspector for enemy... but instead the bullets pass right through

woeful bridge
#

actually sorry, collision.gameObject.GetComponent<Health>();

viral walrus
#

hmm not sure it changed anything

woeful bridge
#

so put it back under OnCollision, and we'll ignore the whole trigger thing

viral walrus
#

ok one sec

woeful bridge
#

so put all that relevant code under OnCollisionEnter2D() instead of OnTriggerEnter2D()

viral walrus
#

done although now its saying it doesnt recognise tag

woeful bridge
#

collision.gameObject.tag?

#

try that

viral walrus
#

hmmm no error there... ill test now

#

is there any way i can use a debug command to make it show taking damage in the console? or should the "current health" float update in the inspector if its taking damage

#

nevermind it works! i love you man i cant thank you enough

#

i spent hours at that earlier

#

im gonna study whatver it is you did to fix it until i understand it for the future

#

thanks again

woeful bridge
#

glad to hear it man

#

I've been in the exact same situation before

#

bit of googling refreshed my memory

viral walrus
#

i only started trying to learn again recently, i figure itll be a lot of trial and error

woeful bridge
#

I think the trigger thing is ultimately useful but yeah it doesn't seem to like to work out of the gate

viral walrus
#

im more of an artist than a programmer 😅

woeful bridge
#

and because it's so similar a lot of documentation blends together

#

it's a very subtle thing especially with that .tag bit

#

with collisions you have to first reference the actual game object, with trigger that's assumed already in the parameter

#

like in the unity documentation that exact thing came up

viral walrus
#

hmmm, i thiiiink i understand, ish

woeful bridge
viral walrus
#

is that so itll show whats happening in the console?

#

i think thats what debug is used for right?

woeful bridge
#

yes

#

debug.log is exceptionally useful

viral walrus
#

i should learn how to use it then 😅

woeful bridge
#

whenever you're writing a new bit of code, it's handy to have it just so you know the program actually gets to that bit

#

I've had errors come up and I've literally just moved a Debug.log("IT GOT ALL THE WAY HERE") around the block of code until I figured out what line messes it up etc.

viral walrus
#

hmmm, i think i understand how to use that then...

#

youve been a great help, im sure well cross paths again at some point but hopefully i can figure out the next problem a bit better myself aha

woeful bridge
#

very versatile as well, you could make it print say Debug.log("Enemy got hit with a bullet, it's taken " + amount + " damage, and its health has went down to " + CurrentHealth + "!")

#

so when you test it, you'll expect the unity console to print "Enemy got hit with a bullet, it's taken 2 damage, and its health has went down to 1!"

viral walrus
#

so i can make references in the debug line to make it show whats happened so far?

woeful bridge
#

yes exactly

viral walrus
#

hmmm im gonna try that now

woeful bridge
#

I think technically stuff like break points and variable watching etc. is cleaner and more robust

#

but it's far more annoying to set up compared to just writing debug.log

#

heavily recommend you clean up and get rid of debug.logs after you're happy with a particular block of code

viral walrus
#

it doesnt seem to like my references

woeful bridge
#

make sure it's in the TakeDamage function

#

like I'd pop that under line 18 in that screenshot with TakeDamage that you posted

viral walrus
#

well "CurrentHealth" is a public float... cant i reference it in a different script?

woeful bridge
#

if you pop that in any other bit of code it'll not work

#

you could, but you'd need to still reference the specific object

#

so I think if you did it under the collision code on your bullet

#

it'd be something collision.gameObject.getcomponent<Health>().CurrentHealth

viral walrus
#

yeah i think then i could reference "Health"

#

so basically i still need to tell it to find out what "CurrentHealth" even means, right?

woeful bridge
#

yeah

viral walrus
#

coooool

woeful bridge
#

if you just say CurrentHealth to the bullet, it hasn't a single clue what you mean

viral walrus
#

right... makes sense when you put it like that aha... so you referenced the class "Health" and then told it to find out what "CurrentHealth" means to that class?

woeful bridge
#

yep

#

also there could be more than one enemy and more than one instance of the Health script as a result

#

also there could be a whole other script that also has CurrentHealth as an example

viral walrus
#

so then would i need to reference gameObject.tag again?

woeful bridge
#

for the debug.log? probably not

#

well

viral walrus
#

right... see i thought thats how id distingush which enemy i mean

woeful bridge
#

ah yes right

#

so yeah, to be clear that tag part is important because like you said you only want it asking for the health script for certain objects

#

if you didn't make that distinction, it could collide with like a wall or a powerup or anything else and be like "here where's your Health script I need whatever integer you have under CurrentHealth"

viral walrus
#

right... but for now i have such little script written that it has nothing to get confused with aha

woeful bridge
#

yep

#

technically you have the player, it could collide with that

#

I know because I've had that happen

viral walrus
#

true, good job i havent given the player health yet xD

#

havnt had a need to yet as my enemy cant hurt me yet

#

thats my next goal

#

but currently my game of "shoot the stationary square 3 times" is really quite captivating... i could win an award

woeful bridge
#

but aye referencing is not the most intuitive thing in the world at first

#

you just gotta force yourself to remember that computers have 0 intuition

viral walrus
#

quick question, so like, as an experienced programmer, if you wanted to make something, lets just say like making an enemy teleport in combat.... would you just be able to figure it out on your own or do you guys look up what other people have done to solve it too?

woeful bridge
#

oh look it up absolutely

#

you never stop googling

viral walrus
#

cause like, i just cant imagine knowing how to build scripts from scratch...

#

which begs the question, how did the first person solve the problems im googling in the first place lol

woeful bridge
#

hell I'm not particularly experienced, I actually came on since I was wanting a second opinion on something for a picross clone (whether using all the button shit that unity gives you for the grid is worth it)

#

oh aye you're not alone in that at all

viral walrus
#

well as far as im concerned, youre a wizard, enjoy that admiration lmao

woeful bridge
#

you will be googling stuff all the time don't worry about it

#

doesn't make you less of a programmer or anything like that, it's all magical hocus pocus to trick a bunch of silicon into thinking and there's no way of remembering all the magic words and minutia for each bit

viral walrus
#

well, hopefully i get my head around it at some point aha

#

its a lot harder than making sprites, thats for sure... and im not even great at that lol

woeful bridge
#

yeah, the bit you do get better at is framing the questions you ask I find

viral walrus
#

im only really trying to learn unity so that i have a reason to make sprites aha