# How to code a non-newtonian spaceship control script?

I'm working on a simple 3D space combat game, and I've decided to go with simplified physics over proper newtonian motion, similar to the space sim Oolite, and more 'arcade' style games. I basically want my ships to move how spacecraft do in Star Wars.

This is what I'm trying to achieve specifically; ability to rotate along each axis, and with solely forward motion relative to the spacecraft. In the case of impacts and collisions I want to spacecraft to move under normal physics, but for any rotation/velocity incurred by the collision to quickly bleed off.

I can find a lot of tutorials that show how to achieve this kind of flight by setting angular drag and such in a standard aircraft controller. This seems like it is a waste of resources however, since you are using the drag equations to cancel out the newtonian thrust equations. Since I'm aiming for hundreds of ships in a single battle I need to keep things as efficient as possible.

So is there a simpler, more efficient way to have this kind of controller?

• uhm... wot.... But yeah, i think you would be best creating a "Normal Plane" controller, then modifying this so it never falls out the world You know, when you stop moving. i cant think of a simply way to achieve what you want though. – Ryan white Aug 17 '16 at 8:56

## 1 Answer

I found out how to do this, so I'll put it up in case anyone else is trying to do the same.

Unity has a function called Transform.Rotate which can be used to rotate a game object around its own axis. I used this for roll, pitch, and yaw. The I used the similar Transform.Translate for forward motion.

• You can do that, but then you shouldn't use Rigidbodies, because these can behave very weird when you manipulate the transform directly. No rigidbodies also means you can't use the Unity physics engine to handle movement after a collision. – Philipp Aug 19 '16 at 11:01
• @philipp Any idea what I should use instead? I do need collisions so it seems I've taken the wrong direction entirely :(. – moran Aug 21 '16 at 3:37
• You should do what the tutorials say: Use the standard physics engine but ramp up the drag parameters. That will give you a more arcade-like feel. When it is too slow (is it really? Have you tested it?) you will have to write your own newtonian physics, implementing only the features you need. – Philipp Aug 21 '16 at 10:10
• @philipp I've pretty much got it working now. I'm using a FixedUpdate and the Rigidbody.AddForce, but putting the drag on the rigid body in the inspector rather than in the script itself, which is much simpler than what the tutorials were doing. – moran Aug 21 '16 at 10:48