• 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 Penfwasaurus · Dec 23, 2013 at 07:55 PM · java

My Spaceship Accelerations not working?

I made a script in c#, which worked fine, then i needed to do a different script which required java, so i rescripted this into Java! This is the java version, for somereason when im holding space to Accelerate, ITS NOT WORKING?? it should be??? help, look at the //acceleration part #pragma strict

     var speed = 0;
     var maxSpeed = 1;
     var minSpeed = 0;
     var breakPower = 0.5f;
     var accelSpeed = 0.1f;
     
     var rotatePower = 1;
 
     // Use this for initialization
     function Start () {
 
     }
     
     // Update is called once per frame
     function Update () {
     
         
         //--------------------------------------------------------
         
         
         //Acceleration
         if (Input.GetKey("space")) {
             speed += accelSpeed * Time.deltaTime;
         }
         // MoveForward At the Speed
         transform.Translate(0, 0, speed);
         
         //Make sure you can only go upto the max speed
         if (speed > maxSpeed) {
             speed = maxSpeed;
         }
         
         //Make sure the slowest you go is your MinSpeed
         
         if ( speed < minSpeed) {
             speed = minSpeed;
         }
         // Braking
         
         if (Input.GetKey("left shift")) {
             speed -= breakPower * Time.deltaTime;
         }
         
         //--------------------------------------------------------------
         
         
         
         //Rotating up + down, make sure your at a high enough speed also
         
         if (speed > 0.1) {
         
         if ( Input.GetKey("w")) {
             transform.Rotate(rotatePower, 0, 0);
         }
         if ( Input.GetKey("s") && speed > 0.35f) {
             transform.Rotate(-rotatePower, 0, 0);
         }
     }        
         
         //Roting The Roll
         
         if ( speed > 0.1) {
         
         if ( Input.GetKey("a")) {
             transform.Rotate(0, 0, rotatePower);
         }
         if ( Input.GetKey("d")) {
             transform.Rotate(0, 0, -rotatePower);
         }
     }        
         //Turning on the flat axis
                 
         if (speed > 0.1) {
         
         if ( Input.GetKey("q")) {
             transform.Rotate(0, rotatePower, 0);
         }
         if ( Input.GetKey("e")) {
             transform.Rotate(0, -rotatePower, -0);
         }
     }    
         
         //-------------------------------------------------------------
     }
 
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

1 Reply

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

Answer by robertbu · Dec 23, 2013 at 07:58 PM

The likely problem is here:

 var speed = 0;
 var maxSpeed = 1;
 var minSpeed = 0;
 var breakPower = 0.5f;
 var accelSpeed = 0.1f;

When you don't specify a type, the compiler infers a type from the parameter. Since you are assigning an integer to 'speed', 'maxSpeed' and 'minSpeed', the compiler makes these variables integers. If an integer was 3, when you add 0.1 to that integer, it is still 3.

You can fix it by changing what is assigned:

 var speed = 0.0;
 var maxSpeed = 1.0;
 var minSpeed = 0.0;

And/or you can specify the type for the variables:

 var speed : float = 0;
 var maxSpeed : float = 1;
 var minSpeed : float = 0;

 

 
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

UnityPlayerActivity vs. UnityPlayerNativeActivity 0 Answers

Will not create the array 0 Answers

enable / disable particle system 1 Answer

Accessing and using Javaclasses from Unity 1 Answer

Unexpected Token BCE0043 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