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 davidflynn2 · Oct 09, 2012 at 03:28 PM · c#cs

Space Craft controller.

I have the following code for my space craft to allow it to fly in space but right now when I press the key to make it move it continues to move in that direction even after you relase the key. I want to change this code to make it so that once the button is released it causes the ship to stop moving in that direcion to give more of a exact contolle.

 var Speed = 1000;
 var TorqueSpeed = 20.0;
 function Update () {
 
 if(Input.GetKeyDown(KeyCode.W)){constantForce.relativeForce.z = Speed * Time.deltaTime;else{
 
 if(Input.GetKey(KeyCode.S)){constantForce.relativeForce.z = -Speed * Time.deltaTime;}else{
 constantForce.relativeForce.z = 0;}}
 //Turn right and left
 if(Input.GetKey(KeyCode.D)){constantForce.relativeTorque.y = TorqueSpeed * Time.deltaTime;}else{
 if(Input.GetKey(KeyCode.A)){constantForce.relativeTorque.y = -TorqueSpeed * Time.deltaTime;}else{
 constantForce.relativeTorque.y = 0;}}
 //Rotate Up and Down
 if(Input.GetKey(KeyCode.E)){constantForce.relativeTorque.x = TorqueSpeed * Time.deltaTime;}else{
 if(Input.GetKey(KeyCode.Q)){constantForce.relativeTorque.x = -TorqueSpeed * Time.deltaTime;}else{
 constantForce.relativeTorque.x = 0;}}
 //Rotate right and left
 if(Input.GetKey(KeyCode.Z)){constantForce.relativeTorque.z = TorqueSpeed * Time.deltaTime;}else{
 if(Input.GetKey(KeyCode.X)){constantForce.relativeTorque.z = -TorqueSpeed * Time.deltaTime;}else{
 constantForce.relativeTorque.z = 0;}}
 }
 
Comment
Add comment · Show 5
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 kmeboe · Oct 09, 2012 at 04:19 PM 1
Share

A real spacecraft will have momentum, right? $$anonymous$$eaning that even if you turn of your thrusters, you will continue moving at the same speed. Are you trying to make your spacecraft stop when you release the keys?

avatar image davidflynn2 · Oct 09, 2012 at 04:22 PM 0
Share

yes I would like to make it so that it has a break a little bit so that you dont have to fight quite so hard to get controlle back of it.

avatar image kmeboe · Oct 09, 2012 at 04:25 PM 1
Share

$$anonymous$$aybe what you want is drag. Have you tried adding more drag (and angular drag) to your rigidbody?

avatar image T27M · Oct 09, 2012 at 04:55 PM 1
Share

I think this should be done in FixedUpdate.

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.FixedUpdate.html

avatar image davidflynn2 · Oct 09, 2012 at 07:29 PM 0
Share

I gave every one here credit because I ended up using a little of what all of you said to make it work.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Griffo · Oct 09, 2012 at 03:52 PM

I think you need

 Input.GetKeyDown
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 davidflynn2 · Oct 09, 2012 at 03:56 PM 0
Share

I tried that on the top one with the w and it dont seem to make a difference.

avatar image davidflynn2 · Oct 09, 2012 at 07:29 PM 0
Share

I gave every one here credit because I ended up using a little of what all of you said to make it work.

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

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Deactivate Controlle of one object and Contoll another 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

PinBall Flippers 1 Answer

Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer


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