- Home /
Rotate particles around player while moving up
I have the following lines of code:
void OnTriggerStay(Collider col)
{
// Keep us at orbitDistance from target
myTransform.position = col.transform.position + (myTransform.position - col.transform.position).normalized * 0.8f;
myTransform.RotateAround(col.transform.position, Vector3.up, 2000 * Time.deltaTime);
StartCoroutine(DisableDrops());
}
This will rotate my particle object around my player. The pivot point of my player is at his feet so it starts rotating around the ground area. I would slowly like to increase its y over time so that it looks like the particles rotate from his feet to his head.
I tried using:
myTransform.Translate(Vector3.up* 10 * Time.deltaTime);
alongside this code, but the particles just get stuck. Is there a way I can achieve this?
IEnumerator DisableDrops()
{
yield return new WaitForSeconds(20.0f);
gameObject.SetActive(false);
}
All this does is disables the object after 20 seconds
What is myTransform? Why not just use transform.Translate(Vector3.forward * Time.deltaTime);
to see if it gets stuck?
myTransform is cached in the awake function for better performance, makes such a big difference if using distance variables.
Transform myTransform;
void Awake()
{
myTransform = transform;
}
So what I have is the exact same as what you suggested.
Answer by aldian · Sep 16, 2015 at 01:32 PM
if you set the position with a nested empy gameobject at his feet and at his head then you can use a smoothdamp
http://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612033940im_/https://answers.unity.com/themes/thub/images/avi.jpg)