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 /
This question was closed Jan 09, 2012 at 05:10 PM by Jessy for the following reason:

http://answers.unity3d.com/questions/203613/movement-in-space-scrip-assistance.html

avatar image
0
Question by illiterate · Jan 09, 2012 at 05:06 PM · rotationjavascriptvector3.anglethrust

Movement in space - Scrip assistance

Hello, im attempting to write a script that allows my topdown spaceship to move about as if it was in space. I.E doesnt stop when the button is released, and when rotated continues on the path it was on untill thrust is applied. So far I have this.

 var ShipTopSpeed:float = 15;
 var RevShipTopSpeed:float = -10;
 var ShipAcceleration:float = 5;
 var ShipDecceleration:float = 1.5;
 var ShipCurrentSpeed:float;
 var ShipRotationPosSpeed:float = 50;
 var ShipRotationNegSpeed:float = -50;
 var ShipRotationAcceleration:float = 5;
 var ShipRotationDecceleration:float = 1;
 var ShipRotationCurrentSpeed:float;
 function Update () {
 
 if(Input.GetButton(‘w’) && (ShipCurrentSpeed < ShipTopSpeed )) {
 NewSpeed = ShipCurrentSpeed + ShipAcceleration;
 ShipCurrentSpeed = NewSpeed;
 }
 if (Input.GetButton(‘d’) && (ShipRotationCurrentSpeed < ShipRotationPosSpeed )){
 NewRotationSpeed = ShipRotationCurrentSpeed + ShipRotationAcceleration;
 ShipRotationCurrentSpeed = NewRotationSpeed;
 }
 
 if (Input.GetButton(‘a’) && (ShipRotationCurrentSpeed > ShipRotationNegSpeed )){
 NewRotationSpeed = ShipRotationCurrentSpeed – ShipRotationAcceleration;
 ShipRotationCurrentSpeed = NewRotationSpeed;
 }
 
 if (Input.GetButton(‘s’) && (ShipCurrentSpeed > RevShipTopSpeed )){
 NewSpeed = ShipCurrentSpeed – ShipDecceleration;
 ShipCurrentSpeed = NewSpeed;
 }
 if (ShipCurrentSpeed > 0){
 transform.Translate(Vector3.forward * Time.deltaTime * ShipCurrentSpeed );
 }
 if (ShipCurrentSpeed < 0) {
 transform.Translate(Vector3.forward * Time.deltaTime * ShipCurrentSpeed );
 }
 
 t    ransform.Rotate(Vector3.up * Time.deltaTime * ShipRotationCurrentSpeed );
 
 if (Input.GetButtonUp(‘d’) ){
 RotateSlow();
 }
 if (Input.GetButtonUp(‘s’) ){
 RotateSlow();
 }
 
 if (!Input.GetButton(‘d’) && (!Input.GetButton(‘a’))){
 if (ShipRotationCurrentSpeed != 0){
 RotateSlow();
 }
 }
 }
 
 function RotateSlow(){
 if (ShipRotationCurrentSpeed != 0){
 if (ShipRotationCurrentSpeed < 0) {
 NewRotationSpeed = ShipRotationCurrentSpeed + ShipRotationDecceleration;
 ShipRotationCurrentSpeed = NewRotationSpeed;
 }
 if (ShipRotationCurrentSpeed > 0) {
 NewRotationSpeed = ShipRotationCurrentSpeed – ShipRotationDecceleration;
 ShipRotationCurrentSpeed = NewRotationSpeed;
 }
 }
 }

Now this does most of what i want it to do, the ship accelerates to its top speed, and if the button is released stays at that speed. The issue starts when I add rotation to the mix. Because of the use of transform.Translate(Vector3.forward Time.deltaTime ShipCurrentSpeed ); as soon as rotation is applied, the ship shoots off in that direction. Is there a function that allows me to record the angle of thrust, and continue using that until a new thrust angle is supplied, slowly decreasing the original thrust angle until the ship is then flying in the new direction.

I'm sure there is but I cant find it, and cant work out a way of doing it with the information I currently have.

Also any simplification is welcome, this is my first bit of Javascript, and my first attempt at this type of thing.

Thanks in advance. Steve.

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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Movement in space - Scrip assistance 1 Answer

Realtime Object Rotation on iPad 0 Answers

Smooth rotation in 90° increments 0 Answers

How To Check If X Rotation Is Between Two Numbers?? 1 Answer

space flying system 3 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