Space Combat Simulator - Camera and Thrust/Roll

Hello there!


So, I'm new to Unity and I'm trying to make a space combat simulator where the player pilots a fighter using the mouse to set the direction (pitch and yaw), two keys to increase or reduce trust (lets make it "W" and "S") and another two keys to "roll" the fighter (lets make it "A" and "D")...~

With that in mind, I've set up the main camera with a Smooth Follow script aimed at the Fighter, and a Mouse Look script in the fighter. But here is when the problem starts, because, the camera doesn't follows the rear of the craft when I move my mouse on the Y axis, but always follows when I move it on the X axis.

//End TL;DR

So, I've come here searching for help in two things:

  1. How can I make the camera be always looking to the rear of the fighter?
  2. How can I setup the thrust and roll for my fighter?

Thank you very much, and have a good day.

more ▼

asked Dec 30, 2011 at 01:16 AM

JPB18 gravatar image

155 76 70 75

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

For the camera -> Take the smooth follow off of the camera, child the camera to the vehicle, then position the camera where you want it.

For the flight -> quick-code to get you started (UnityScript/Javascript) ->

@HideInInspector var myRigid : Rigidbody ; //used for caching this objects rigidbody   var thrust : float = 100.0 ; var roll : float = 100.0 ;   function Start(){ myRigid = rigidbody ; }   function Update(){ FlyMeToTheMoonAndLetMePlayAmongstTheStars(); }   function FlyMeToTheMoonAndLetMePlayAmongstTheStars(){

//roll control for left/right arrow keys, and/or 'a'/'d' myRigid.AddRelativeTorque(0,0, Input.GetAxis("Horizontal") (roll Time.deltaTime)) ;

//thrust control for up/down arrow keys, and/or 'w'/'s' myRigid.AddRelativeForce(0,0, Input.GetAxis("Vertical") (thrust Time.deltaTime)) ; } //NOTE : the "Input.GetAxis...." parts might need changed to a negative value, I can't remember what the default buttons are for negative/positive axis. //e.g. if you push left, but it rolls right, change it to " - Input.GetAxis.... "

more ▼

answered Dec 30, 2011 at 01:49 AM

Lo0NuhtiK gravatar image

6.4k 5 18 58

Thank you very much the part of the Thrust is now beginning to look good, and the camera is now behind the fighter (the roll still ain't work, though)...

If you don't mind I make another question is on how to smooth the camera turn a bit so that it makes a bit of angle from the fighter, but always keeps the thrusters focused?

Dec 30, 2011 at 02:22 AM JPB18

Nope, reached to increase the value up to 1000000.0 and still no Roll...

Dec 30, 2011 at 02:51 AM JPB18

So is there a way to keep the F-302 pointing at the mouse, and "Roll"?

Dec 30, 2011 at 02:59 AM JPB18

Well I've found out someone with exactly this problem... Maybe this would fix it?


Or is there a better way?

Dec 30, 2011 at 03:27 AM JPB18

True... I admire that... Of course I'll make my own modifies and first try to interpretate the code myself! But please share your discoveries! :D

Dec 30, 2011 at 03:40 AM JPB18
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Dec 30, 2011 at 01:16 AM

Seen: 2506 times

Last Updated: Dec 30, 2011 at 04:19 AM