#Getting particle emissions working

1 messages · Page 1 of 1 (latest)

modest creek
#

Il try to help you here its so busy in the other chat

mortal spear
#

okay

modest creek
#

The only time im seeing a transform be used is when player is being accessed

#

Or is trying tm be accessed

mortal spear
#

wait let me send the piece of code i think is giving me this error

modest creek
#

Okay

mortal spear
#
 using UnityEngine;
  
 public class Enemy : MonoBehaviour
 {    
 public Transform target;
 public float Roffset = 90f;
  
 private void Update()
 {
     if (Vector3.Distance(transform.position, target.position) > 1f)
     {
         RotateTowardsTarget();
     }
 }
  
 private void RotateTowardsTarget()
 {
     var offset = Roffset;
     Vector2 direction = target.position - transform.position;
     direction.Normalize();
     float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;       
     transform.rotation = Quaternion.Euler(Vector3.forward * (angle + offset));
 }
 }
#

this is for the enemy rotation

modest creek
#

Wait

#

Send the whole error

mortal spear
modest creek
#

Thats not the whole thing

#

Click on the error

mortal spear
modest creek
#

Okay

#

Look see the blue words?

mortal spear
#

yes?

modest creek
#

Thats where the error is happening

#

The enemy script on line 10

#

In Update

mortal spear
#

perhaps this line of code is still attempting to access the player after my particle script has destroyed the player?

modest creek
#

Maybe

#

Could also be RotateTowardsTarget()

#

Cause your calling that in there

mortal spear
#

yeah

modest creek
#

Try temporarily taking that out of possible

#

Then run the code and if the error happens again then we know

mortal spear
#

this part of the code?

modest creek
#

Nope

#

RotateTowardsTarget()

#

Take that call out for a sec

mortal spear
#

alright i'll just temporarily disable the entire script since RotateTowardsTarget() is basically the only function

modest creek
#

No

#

Dont

mortal spear
#

okay

modest creek
#

We trying to see if that is trying to call something or if its the if statement

#

Just take the call out and run the game

#

Not the whole function itself

mortal spear
#

ohh

#

sorry i'm really dumb

modest creek
#

What?

mortal spear
#

?

modest creek
#

Thats what im wondering 🤔

mortal spear
#

you meant removing RotateTowardsTarget from the if statement right?

modest creek
#

Yes

mortal spear
#

yeah it's still giving me the error

modest creek
#

Okay might as well add it back

mortal spear
#

okay done

modest creek
#

So target is being destroyed

#

Thats the only option

#

Becuase transform.position would do that for its own object

#

What is target?

mortal spear
#

the player

modest creek
#

Can you show me when your destroying the player?

mortal spear
#

after the player collides with the enemy

modest creek
#

Or here lets do this

mortal spear
#

in this snippet

modest creek
#
{
       Your if statement 
}```
mortal spear
#

okay

#

something like this?

modest creek
#

Put the if(Vector3...) in side of the if statement

mortal spear
#

ok

modest creek
#

Did that fix the error?

mortal spear
#

let me check

#

i'm really sorry for being so dumb but i'm not sure what you mean by putting the if statement inside of the if statement

modest creek
#

Thats okay

#

Darn auto correct

#

Sometimes mobile is annoying

mortal spear
#

oh

modest creek
#

See your first if statement?

mortal spear
#

yes

modest creek
#

Copy the whole thing!

mortal spear
#

okay

modest creek
#

Then delete it

mortal spear
#

okay

modest creek
#

Then place your curser in the second if statement and do ctrl + v

#

Then show me your code

mortal spear
modest creek
#

Yes but you have it looking weird

mortal spear
#

oh

modest creek
#

Usually you want to indent that stuff

#

So like go in front of the second if statement and hit tab

mortal spear
#

ah okay

modest creek
#

Then do that for both curly brackets for that if statement

mortal spear
modest creek
#

Good not the rotate towards

#

Thats how people usually make their code look more neat and clean

mortal spear
#

yeah it does look neat

modest creek
#

Now that should fix it

#

Try the error now

mortal spear
#

still getting it

#

still saying the same thing as before even when i check the whole error

modest creek
#

Ctrl + z to undo all that

#

I dont know what to do

#

Sorry buddy

#

I should take a break

#

I might ping you later to try and help you again

mortal spear
#

alright

#

but thank you anyway

modest creek
mortal spear
#

particle emissions still not working, still getting that same error upon collision

#

i think i'll keep trying today, will keep you updated

mortal spear
#

i think i will resort to not destroying the player, but once it collides it'll give a game over UI so it won't need to be destroyed anyway

#

will play the particle, maybe some knockback for it to look a bit nicer

#

and then the game over UI turns on

#

now i just need to get the particles working

#

you know what

#

i'm just going to scrap this script and make a new one

#

coding is so painfully tedious holy crap

#

i solved the error we are trying to fix

modest creek
modest creek
mortal spear
modest creek
#

Try calling particleSystem.Stop() before particleSystem.PLay()