public Vector3 GetEmitRotation(EffectNode node) { Vector3 ret = Vector3.zero; //Set Direction: if (Layer.DirType == DIRECTION_TYPE.Sphere) { ret = node.GetOriginalPos() - Layer.DirCenter.position; if (ret == Vector3.zero) { //use random rotation. Vector3 r = Vector3.up; Quaternion rot = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); ret = rot * r; } } else if (Layer.DirType == DIRECTION_TYPE.Planar) { ret = Layer.OriVelocityAxis; } else if (Layer.DirType == DIRECTION_TYPE.Cone) { //if emit uniform circle, the rotation should be spread from the center. if (Layer.EmitType == (int)EMITTYPE.CIRCLE && Layer.EmitUniform) { Vector3 dir; if (!Layer.SyncClient) { dir = node.Position - (node.GetRealClientPos() + Layer.EmitPoint); } else { dir = node.Position - Layer.EmitPoint; } Vector3 target = Vector3.RotateTowards(dir, Layer.CircleDir, (90 - Layer.AngleAroundAxis) * Mathf.Deg2Rad, 1); Quaternion rot = Quaternion.FromToRotation(dir, target); ret = rot * dir; } else { //first, rotate y around z 30 degrees Quaternion rotY = Quaternion.Euler(0, 0, Layer.AngleAroundAxis); //second, rotate around y 360 random dir; Quaternion rotAround = Quaternion.Euler(0, Random.Range(0, 360), 0); //last, rotate the dir to OriVelocityAxis Quaternion rotTo = Quaternion.FromToRotation(Vector3.up, Layer.OriVelocityAxis); ret = rotTo * rotAround * rotY * Vector3.up; } } else if (Layer.DirType == DIRECTION_TYPE.Cylindrical) { Vector3 dir = node.GetOriginalPos() - Layer.DirCenter.position; float dist = Vector3.Dot(Layer.OriVelocityAxis, dir); ret = dir - dist * Layer.OriVelocityAxis.normalized; } return(ret); }
public Vector3 GetEmitRotation(EffectNode node) { Vector3 ret = Vector3.zero; //Set Direction: if (Layer.DirType == DIRECTION_TYPE.Sphere) { ret = node.GetOriginalPos() - Layer.DirCenter.position; if (ret == Vector3.zero) { //use random rotation. Vector3 r = Vector3.up; Quaternion rot = Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)); ret = rot * r; } } else if (Layer.DirType == DIRECTION_TYPE.Planar) { ret = Layer.OriVelocityAxis; } else if (Layer.DirType == DIRECTION_TYPE.Cone) { //if emit uniform circle, the rotation should be spread from the center. if (Layer.EmitType == (int)EMITTYPE.CIRCLE && Layer.EmitUniform) { Vector3 dir; if (!Layer.SyncClient) dir = node.Position - (node.GetRealClientPos() + Layer.EmitPoint); else dir = node.Position - Layer.EmitPoint; Vector3 target = Vector3.RotateTowards(dir, Layer.CircleDir, (90 - Layer.AngleAroundAxis) * Mathf.Deg2Rad, 1); Quaternion rot = Quaternion.FromToRotation(dir, target); ret = rot * dir; } else { //first, rotate y around z 30 degrees Quaternion rotY = Quaternion.Euler(0, 0, Layer.AngleAroundAxis); //second, rotate around y 360 random dir; Quaternion rotAround = Quaternion.Euler(0, Random.Range(0, 360), 0); //last, rotate the dir to OriVelocityAxis Quaternion rotTo = Quaternion.FromToRotation(Vector3.up, Layer.OriVelocityAxis); ret = rotTo * rotAround * rotY * Vector3.up; } } else if (Layer.DirType == DIRECTION_TYPE.Cylindrical) { Vector3 dir = node.GetOriginalPos() - Layer.DirCenter.position; float dist = Vector3.Dot(Layer.OriVelocityAxis, dir); ret = dir - dist * Layer.OriVelocityAxis.normalized; } return ret; }