简体   繁体   中英

How to improve trajectory of rocket (Unity 3d)

I have a sphere with attached empty object, the object is on the planet's surface, rocket launches from this empty object. Sphere is rotating. My rocket can fly by spiral trajectory from a center of it's instantiating place. The problem that I can't resolve is that rocket's trajectory is independent from planet's rotation. This is Update() function for the rocket:

void Update () {
     angle += speed * Time.deltaTime;
     x = Mathf.Cos (angle) * radius;
     z = Mathf.Sin (angle) * radius;
     rb.velocity = new Vector3(x,0.0f,z);
     radius += stepOfRadius;
 }

What I have: 在此处输入图片说明

How I want it to be (without moon and returning back to Earth): 在此处输入图片说明

I don't know a lot about unity3d but x and z seem to be the components of position and not velocity.

If it's possible, try to replace

rb.velocity = new Vector3(x,0.0f,z);

by

rb.position = new Vector3(x,0.0f,z);

or

Vector3 position(x,0.0f,z);
rb.MovePosition(position);

Otherwise, you can keep rb.velocity by defining this components of velocity (I suppose speed is an angular velocity):

 x = (stepOfRadius/Time.deltaTime) * Mathf.Cos(angle) - radius * speed * Mathf.Sin(angle);
 z = (stepOfRadius/Time.deltaTime) * Mathf.Sin(angle) + radius * speed * Mathf.Cos(angle);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM