What should I use to make a rocket/an airplane move?

Hello!

I’m trying to make an object which is very similar to rockets or airplanes: it flights in the direction of its “nose” :slight_smile: I’d like to make a simple arcade-style control for it.

I feel lost in docs and tutorials, and I can’t understand, what components and methods I should use for my purpose. Should I take some methods of Rigidbody or it’s a job for Transform? Please, help me to find suitable pages in documentation.

do the tutorials in learn… game dev isnt for everyone. If you’re getting lost in docs/tutorials, you might not be up to the task.

@aa-novik

There is a tutorial about adding forces with the physics engine-- see if you can make sense of that. Generally speaking, you’ll need a Rigidbody component, and you’ll need to use the Rigidbody.AddForce() function. If you’re still confused, you may need to go to some of the introductory tutorials, if you haven’t already. In case you didn’t see them, you can find tutorials for specific topics near the bottom of the tutorials page.

Once you have a better grasp of the basic concepts, you’ll be able to ask more specific questions (this is the key), by which help will be easier to find. Keep using the manual and API as you learn to better understand how to use them to look things up.

1 Like

Hyblademin, thanks for your answer. Maybe I’ve described the problem very unclear, so I’ll try to explain it again.

Of course, I watched many of Unity tutorials and videos on YouTube, as well as I read documentation. So I have some understanding of Transforms, Rigidbodies and their methods.

But I’d like to ask what is the simplest way to make this arcade-style control for the airplane or rocket. Now I have two main ideas.

  1. I can use Rigidbody and its AddForce(). As I see, it is not the simplest way, because I have to take into consideration many forces from different directions, and it seems to be very hard to balance them.
  2. (And this is what I’m trying to make in my project.) I can use isKinematic variable of Rigidbody, rotate my object using transform.eulerAngles and make it go forward changing transform.position.

But I could miss something very important in my thinking, so I need your advice to make a right desicion: what way would you choose and why?

Try AddRelativeForce(). It allows you to specify a direction in the rocket’s coordinate system, so that it always propels the rocket in a direction based on which way it’s facing (up, most likely). Now you can use AddTorque() (or AddRelativeTorque() if it’s more convenient) to handle the rotation. You can rotate the rocket however you want with this method, and it will always propel itself in the same relative direction.

If you want to design a special rocket with more than one thruster, you can just use another AddRelativeForce() for each one.

1 Like

Thank you very much for help. I’ll try to make both of variants (forst using Transform and second using Rigidbody) and compare their behavior in different situations.

Hyblademin, OK, now I’m trying to write controller using AddRelativeForce() and AddRelativeTorque(). You wrote:

But it works like a summ of “old” and “new” forces (and this is logical), so when, for example, my rocket turns right, it continues to fly in old direction during a pretty long time.

This is what I meant by phrase “many forces from different directions, and it seems to be very hard to balance them”. Or here is some short way to do it? Or I just use AddRelativeForce() in a wrong way?

This is the expected behavior of a Rigidbody under these conditions, and likewise of a real rocket-like object. If you don’t want it to drift so far, increase the drag on the Rigidbody (you can do this in the inspector). Also add angular drag if you don’t want the same problem to happen with rotation.

Be aware that this is not what forces from different directions would do, and there are no old or new forces-- there is only current velocity, and current acceleration (caused by forcing the object). When applying a force to an object, the acceleration is some value, which changes the velocity. When you stop applying the force, the acceleration becomes 0, which means the velocity stops changing; in other words the object continues to move in the same direction after the force stops.

Adding drag will reduce the velocity each frame when it is not all-0.

For our reference: Is this a rocket in space? Or one launching off of the ground?

By the way, posting your code using code tags will help us help you.

Oh, yes, I see. Sometimes my explanations could be hard to understand, sorry for my English :blush:

It is a rocket in space. The problem is that using Rigidbody brings new questions, so I need to play with different values to understand it better. Thank you for help, I really appreciate it.

OK, I have an object, and it should turn like a plane (not physically, but visually). When it turns right or left, it tilts like this:

float hAxis = CrossPlatformInputManager.GetAxis ("Horizontal");
rb.AddTorque (transform.forward * -hAxis * 5);

This code just moves a rocket around its forward vector. To turn it I’d like to use AddTorque with another vector. This is what want to do:
2848793--208076--Untitled-1.png
But even if I use Vector3, it rotates like around transform.up, changing transform.rotation.x coordinate. But I need object’s transform.forward to be always parallel to the world forward vector. This is my code:

float vAxis = CrossPlatformInputManager.GetAxis ("Vertical");
float hAxis = CrossPlatformInputManager.GetAxis ("Horizontal");
rb.AddTorque (Vector3.up * hAxis * 5);
rb.AddTorque (transform.forward * -hAxis * 5);

What should I do to rotate an object around green axis from my picture?

For example, working with Transform my object turned right like this:

rotationAngleY = transform.eulerAngles.y;
rotationAngleZ = transform.eulerAngles.z;
rotationAngleY += hAxis * rotationAngleZ * turnSpeedY * Time.deltaTime;
rotationAngleZ += hAxis * turnSpeedZ * Time.deltaTime;

I removed some IFs (which help not to exceed boundary values or turn back to zero and so on) from my code just to make it clearer.