- Home /
Using legacy particles and transform.LookAt()
I'm trying to create a cannon enemy that faces the player and fires a particle. When the particle collides with the player, the player dies. I was fudging around with quaternions and atan2 before, but that didn't work out, so I started using transform.LookAt() on the enemy itself and while that properly rotates the enemy to face the players, it screws with the particles for some reason. The particles now shrink and fade out just before they reach the player and depending on the location of the player they sometimes fly off into a random direction. Does anyone know why this occurs and if there's a way to fix it so that the particle emitter emits particles at their proper speed and size without fading out before reaching the player?
You'll have to post a screencap of your particle setup. You might try toggling your world/local setting.
I'm new to Unity so I'm not familiar with all the nuances of the particle systems yet.
And here's the code managing the enemy rotation:
protected void Update$$anonymous$$ovement(float deltaTime){
//rotate the enemy to face the player if the player is within a certain range
Vector3 enemyPos = new Vector3(this.x, this.y, this.z);
Vector3 playerPos = new Vector3(0,0,0);
if(controller.playerEntity!=null)
{
playerPos = controller.playerEntity.transform.position;
}
Vector3 distance = new Vector3(0,0,0);
distance.x= playerPos.x-this.transform.position.x;
distance.y= playerPos.y-this.transform.position.y;
float dist = distance.magnitude;
eTransform.LookAt(playerPos);
}
and here's a picture of the particle itself. It doesn't travel much past this point. It just travels slower and slower until it fades out.