Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by user-3343 (google) · Jun 30, 2010 at 09:18 AM · realisticspaceflight

Realistic control

Hi, i'm making a space game with some realism but am having difficulty working out the script for the ships. The problem is there is no gravity so the ship is always moving and I need to be able to move the mouse around independently (with the ship in motion) and only when thrust is pressed will the ship change course (in the direction the mouse is then pointing to and altered by inertia) rather than the ship constantly following the mouse position.

Here is my script so far:

var rSpeed = 1.0; // **Scale. Speed of the movement**

function FixedUpdate () { MousePosition = Input.mousePosition; MousePosition.x = (Screen.height/2) - Input.mousePosition.y; MousePosition.y = -(Screen.width/2) + Input.mousePosition.x; transform.Rotate(MousePosition Time.deltaTime rSpeed, Space.Self); rigidbody.freezeRotation=true; }

var flyingSpeed = 0; var minThrust : float= 0; var maxThrust : float = 1000; var Accel = maxThrust / 4; var Jumpspeed = maxThrust * 5;

var turnSpeed = 10;

function Update () { //Accelerate the ship useing the thrust button. if(Input.GetButton("Thrust")){
flyingSpeed = Accel + Mathf.Clamp(flyingSpeed, minThrust, maxThrust - Accel); } //decelerates the ship till stop. if (Input.GetButton("Decellerate")){ flyingSpeed = -Accel + Mathf.Clamp(flyingSpeed, minThrust +Accel, maxThrust );}

if(("Thrust")){ rigidbody.velocity = transform.forward Time.deltaTime flyingSpeed; //Apply velocity in Update()

} }

Thanks for any help with this.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by _Petroz · Jun 30, 2010 at 10:36 AM

If you want realism you could just use something like:

if (Input.GetButton("Thrust"))
{
    rigidbody.AddRelativeForce(Vector3.forward * Accel * Time.deltaTime)
}
if (Input.GetButton("Decellerate"))
{
    rigidbody.AddRelativeForce(Vector3.forward * -Accel * Time.deltaTime)
}

There is no friction in space, so in effect there is no maximum speed. Technically there is a limit as you approach the speed of light, in which case you will have to take into account the distortion of light including blue/red shift to have realism.

I have played around with this stuff in the past and this makes for a very unplayable game. It's is much easier if you make it more like an aeroplane where turning will change the direction of motion.

FYI "thrust" is a measure of force not speed. F = ma.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-3343 (google) · Jun 30, 2010 at 05:19 PM 0
Share

Thanks, the limit for speed will be availability of fuel. This does apply force in a direction but once thrust is pressed and released the force should continue in the same direction (rather than cease) and is still linked to the mouseposition all the time.

avatar image _Petroz · Jul 01, 2010 at 09:06 AM 0
Share

A limit of fuel would mean you would stop accelerating when you run out fuel. You would continue at whatever speed you are traveling forever. You would be unable to stop.

avatar image
0

Answer by runevision · Jun 30, 2010 at 11:57 AM

Petroz's answer seems to do what you are asking about. If you want to cap the max speed as well, just use:

if (rigidbody.velocity.sqrMagnitude > maxSpeed * maxSpeed)
    rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Real time high quality interactive liquids 1 Answer

How do I get real-time, realistic shadows and other effects with Unity 5 Free? 1 Answer

Center of mass alternative? 1 Answer

Getting 'Real' behavior through physics settings 1 Answer

which settings are the best to simulate real sunlight ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges