- Home /
Spaceship Control
I have been working on my small space game I have and I got my test ship and a script (below) and got my little ship to fly and twist and all that fun stuff (yay me) But I can't seem to fix the one small problem I have. When I give it power to start moving it just keeps going unless I try to move backwards. Is there some easy way with out having to make another script to make it so that turning, rolling, boosting ect ect. will only keep doing so as long as I am holding it's key?
using this tutorial and script below. http://stopsecretdesign.wordpress.com/2011/09/19/unity-spaceship-tutorial/
What I want it to act like below. from the same guy who made the tutorial http://dl.dropbox.com/u/40580649/Spaceflight/Spaceflight.html
Answer by lil_billy · Oct 29, 2012 at 05:09 PM
ROFL there is no friction in space :D
so if you want it to decelerate you have to make it so
havent you ever watched a space film where the pod is in space and they are rotating it with those little jets on the side and then in order to stop the rotation they fire the jets on the opposite side.
In other words the Fattie was right :D
Now since you seem to be putting emphasis on this being a space controller, if you are going for realism i would keep it the way you have it and force the player to have to manually halt their motions (as they would have to in space). Now if you dont want that you could do as fattie said and apply an opposing force, though doing that is massively inefficient since you would essentially be using a physics calculation to cancel the effects of another physics calculation when you could have just lerped the rotation for a fraction of the processing.
I believe the same guy who made the tutorial you are using also made a regular earth bound flight project. Which you could use that controller and it would be more in keeping with the behaviors you want, just not realistically space flight.
Hmmmm thanks for the input guys :) I tried what Fattie said in the below quote and it did nothing that I can see to change my endless spinning and turning etc. Now it did make it so that I can't ever stop the sucker it takes ages to slow it down....
"
var turnspeed = 5.0; var speed = 5.0; private var trueSpeed = 0.0; var strafeSpeed = 5.0;
function Update () {
var roll = Input.GetAxis("Roll"); var pitch = Input.GetAxis("$$anonymous$$ch"); var yaw = Input.GetAxis("Yaw"); var strafe =
Vector3(Input.GetAxis("Horizontal")*strafeSpeed*Time.deltaTime, Input.GetAxis("Vertical")*strafeSpeed*Time.deltaTime, 0);
var power = Input.GetAxis("Power");
//Truespeed controls if (trueSpeed < 10 && trueSpeed > -3){ trueSpeed += power; } if (trueSpeed > 10){ trueSpeed = 9.99; } if (trueSpeed < -3){ trueSpeed = -2.99; } if (Input.Get$$anonymous$$ey("backspace")){ trueSpeed = 0; }
rigidbody.AddRelativeTorque(pitch*turnspeed*Time.deltaTime, yaw*turnspeed*Time.deltaTime, roll*turnspeed*Time.deltaTime); rigidbody.AddRelativeForce(0,0,trueSpeed*speed*Time.deltaTime); rigidbody.AddRelativeForce(strafe);
rigidbody.AddForce( -0.20 * rigidbody.velocity );
}
" I am very new to scripting so maybe I added it in the wrong place? or just need to change the values more.
And I don't want realistic space flight as to the counter trust. As well I looked about for the earth bound flight project you said he had and I could not find anything that was showing how to go about doing it. Do you have a link by any chance?
Answer by Stopsecret · Oct 31, 2012 at 09:35 PM
Hi, just in case you're curious, I'm the guy who made that script :P First off, thanks for linking me, second off, lil_billy is right, there is no friction in space :) If you want realism, then this script ought to do it. However if you want arcade style, then I recommend (this is important) turning up rigid body drag and angular drag. This ought to make it harder to turn (so turn up the turnspeed, speed, and strafe speed). Hope this helps!
-Stopsecret
Answer by hardcorebadger · Feb 28, 2018 at 08:54 PM
Hey! - not sure if this will help, but for a more arcade-feeling super smooth spaceship controller - this asset might help:
Basically, it has a pretty versatile script to do LERP based cam following of the ship. This is kind of like a normal Smooth Follow, except you get it in full 3D, so the ship can go fully upside down, etc. The controls are easily changeable, which I did myself, but the default is that the ship is continually moving and you use arrow keys for pitch/yaw.
https://assetstore.unity.com/packages/3d/vehicles/space/low-poly-space-ship-ultra-smooth-360-controller-111640
Your answer
Follow this Question
Related Questions
Floating Point wiki script Implementation 2017 0 Answers
Advice on my Ship AI... 4 Answers
Difficulties with "Moving the Space, Not the Player" 0 Answers
Making Top-Down spaceship movement, getting current speed, acceleration, without rigidbody! 1 Answer
Freelancer of Freespace type Enemy Ai 2 Answers