Arcade Style (ChopLifter) Demo - need help with tilting chopper

Hey everyone,

This post is to improve my hobby work on the finer movement of the players helicopter.

I have made the basics to a choplifter clone in 3d however it slides along the X dimension in a 2D manner.
The game works along a Z axis with other objects.

Example shot near the bomber

I am using rigid bodies and physics to push things around. Simple collisions and collisions with magnitude force applied etc.

DEMO
A playable demo ( http://dl.dropbox.com/u/3053655/resQ/resQ.html ) of what I have so far with my own crafted sounds etc… and using the “Detonator” explosions can be linked to above in a web player.

The current controls are
wasd/arrowkeys to move around, e key to rotate directions, left and right mouse for weapons. I find it a lot of fun already but would like to fix some things that bug me.

( Ben Throop ) you rock for DETONATOR. http://variancetheory.com/
Also big shout out to the chat room for help on other areas. Mainly NCarter and mike_mac for their great support.

Chopper Details -

The chopper consists of primitives and a gameObject like this :

Player - rigid body attached and collisions here to this gameObject

  • pivot - a mesh
  • body - attached to this is the propellers etc.

Question - SLIGHT TILT whilst still moving forward.

I want to tilt the chopper slightly according to the Left Right direction however retaining the forward thrust of the physics without the slight force down. The tilt should stabilise itself after the player lets go of the thrust application.

I get weird distortions when I apply an ugly hard coded tilt on the key press.
Is there a way to prevent that? Is that a case of the limbs being offset and being rotated from the parent object?.

UnityJS
http://pastebin.com/q3RER9pc

I stripped out all the junk of my main file and have a mini script.
I realise that the game object find is slow, I need to replace those at some stage.

An example image of the distortion for clarity.

NOTE*
I have had a look at the Helicopter example posted in the vehicle links on someones site but I fear it is beyond the scope of a simple arcade action simulation. Please don’t just link me to code examples like that and hope it will solve it. I have searched a few forums for unity and some posts are close but not quite what I need.

PS Why did i think maths was stupid at school and respect it so much now as an old fart :slight_smile:

The answer to your first part, is that you need to parent all of this to a single object. That single object is your base that you move everything around by. So when you tilt it, it is all tilting locally.

Can you post the script for the entire chopper. I assume there is alot of optimization that needs to happen in that code.

For a chopper, I would use math. It is very hard to hang an object solely by physics. You can do a physics/math hybrid to maintain the physics usage and still keep control over your object. Lerping the rotation is the best way to go.

Hi BigMisterB,

The whole point of this exercise is to use the physics with the old pixel style using 3d objects.
If you played the demo, the game is basically complete bar a few minor visual tweaks with movement, the chopper tilting.
I don’t need realism just arcade realism if you get my drift.

I removed all of the external chopper code and the post above is the basic movement to the chopper.

If you want I can post the main file but I doubt its going to help you any more then the example above.
I removed the spawning of dynamic objects.
http://pastebin.com/1a9Cjd0y

That script above is just the main script, there are others for collisions etc., however I have those covered.
I applied this to my main chopper object as a test and it works in the positive but fails on the negative like below.

// Apply ugly Tilt
GameObject.Find(“player”).transform.Rotate(0, 0, -0.5);

It made the camera rotate with the chopper as I have two cameras attached to the chopper so I may need some code to position the camera instead of relying on the grouping of the cameras. one problem creates 5 others :wink:

I don’t understand the lerp well enough, is it finding an angle over 360?

The time-lapse might prevent me from replying for a while as its late here.

Anyone else competent to advise without suggesting something away from the problem at hand or asking me to post things twice?

Question 2:
What makes this script jitter over just dropping the camera onto the player.
http://pastebin.com/Mvv0ui43

Dropping the camera onto the player as a child is far smoother.

Question 3:

GameObject.Find(“/Player/pivot”).transform.Rotate(0, 0, -0.3);

How can I clamp the -0.3 and 0.3 rotations.

GameObject.Find(“/Player/pivot”).transform.Rotate(0, 0, Mathf.Clamp(-0.3, -0.3, -0.9));

This doesn’t appear to work.

GameObject.Find(“/Player/pivot”).transform.Rotate(0, 0, Mathf.Clamp(-0.3, -0.3, -0.9));
Mathf.Clamp(-0.3, -0.3, -0.9));
-0.3, -0.3,

double negative?

Maybe I am not asking the correct question.

How can I rotate an object’s Z rotation in a positive way with one key and negative way with one key and prevent it from going too far or spinning over.

A boat when it takes off tilts up at the front.
A helicopter when it takes off can tilt forward.
I want to achieve exactly that effect.

Well, when the person is pressing the forward button, have it check if it’s tilted forward beyond 0.3, if so, then make it 0.3 else make it rotate by 0.3 * Time.deltatime ?

I don’t understand, would you mind demonstrating with a working code snippet.

I’m afraid I’m at work :frowning: But when I get home I’ll poke about with it and see if I can get a working system for you.

Time.deltatime is fantastic for creating smooth actions, as it moves an object the amount it would have during the time it took to render the frame. So your chopper will pitch nicely when coupled with a rotation function. But, I’m sure you knew all that.

3d maths is not my strong point.
I hope to hear from you later or someone who can just put me out of my mental misery on something I know should be so simple.

any dimensional maths is not my strong point :stuck_out_tongue: But I get by from trial and error :stuck_out_tongue: I’ll get back to you asap. :slight_smile:

I made a pictograph of the problem in case that helps.

Mike, Blitz and lihis helped me solve it mate, you are off the hook.

http://pastebin.com/nKRnL0vC

Ah okay :stuck_out_tongue: I was only just looking into it, I had other thing to sort out prior. Good to hear :slight_smile:

thanks for your help Markus! btw mate.

Ok now onto the jittering of Question #2.

http://pastebin.com/Mvv0ui43

I found this from another post and using it in my initial camera updates.

There is a tiny annoying jitter pulse in the movement, compared to my older camera that was just dropped onto the player as a hard linked child.
I thought it might have been me using gameObject find so I removed them all and replaced them with hand linking transforms.

What produces that “feature” :P?

btw, each fix will be playable in the demo way above as they are corrected.

If you parent or follow a rigid body of any kind, you need to set that rigid body to interpolate, otherwise it will jitter due to fixedupdate being a different rate to the camera. In addition if you are moving the camera to the rigidbody and not parenting it, perform the action in Update, ensuring again interpolate is checked for the physics body.

Hi Hipz.

Thank you for your sage advice.

I set the only rigidbody on the players mesh and it still appears to do the same thing. I am in update as well.
I will check tomorrow when the head is not midnight fuzzy.