#Getting particle emissions working
1 messages · Page 1 of 1 (latest)
okay
The only time im seeing a transform be used is when player is being accessed
Or is trying tm be accessed
wait let me send the piece of code i think is giving me this error
Okay
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
yes?
perhaps this line of code is still attempting to access the player after my particle script has destroyed the player?
yeah
Try temporarily taking that out of possible
Then run the code and if the error happens again then we know
this part of the code?
alright i'll just temporarily disable the entire script since RotateTowardsTarget() is basically the only function
okay
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
What?
?
Thats what im wondering 🤔
you meant removing RotateTowardsTarget from the if statement right?
Yes
yeah it's still giving me the error
Okay might as well add it back
okay done
So target is being destroyed
Thats the only option
Becuase transform.position would do that for its own object
What is target?
the player
Can you show me when your destroying the player?
after the player collides with the enemy
Or here lets do this
in this snippet
{
Your if statement
}```
Put the if(Vector3...) in side of the if statement
ok
Did that fix the error?
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
oh
See your first if statement?
yes
Copy the whole thing!
okay
Then delete it
okay
Then place your curser in the second if statement and do ctrl + v
Then show me your code
Yes but you have it looking weird
oh
Usually you want to indent that stuff
So like go in front of the second if statement and hit tab
ah okay
Then do that for both curly brackets for that if statement
Good not the rotate towards
Thats how people usually make their code look more neat and clean
yeah it does look neat
still getting it
still saying the same thing as before even when i check the whole error
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
Did you get it figured out?
nope
particle emissions still not working, still getting that same error upon collision
i think i'll keep trying today, will keep you updated
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
Yes it is
Good
i still need to get particles working
Okay
Try calling particleSystem.Stop() before particleSystem.PLay()