Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by panos12 · Sep 06, 2015 at 08:22 PM · scripting problemscript.shipboat

Problem with a ship controller script

Hi,I am making a ship game and I have a ship controller I have found online but I have a problem.when i press the up arrow the vessel is developing speed to the right and on the down arrow on the left duno why its happening any ideas?Rudder is working fine.

http://prntscr.com/8db5jm

here is the code:

 var speed = 1.0;
 
 var acceleration = 1.0;
 
 var maxspeed = 2.0;
 
 var minspeed = -0.25;
 
 var heading = 0.0;
 
 var rudder = 0.0;
 
 var rudderDelta = 2.0;
 
 var maxRudder = 6.0;
 
 var bob = 0.1;
 
 var bobFrequency = 0.2;
 
 
 
 private var elapsed = 0.0;
 
 private var seaLevel = 0.0;
 
 private var rudderControl;
 
 private var rudderAngle = 0.0;
 
 
 
 function signedSqrt( x ){
 
     var r = Mathf.Sqrt(Mathf.Abs( x ));
 
     if( x < 0 ){
 
         return -r;
 
     } else {
 
         return r;
 
     }
 
 }
 
 
 
 function Update () {
 
     // Bobbing
 
     elapsed += Time.deltaTime;
 
     transform.position.y = seaLevel + bob * Mathf.Sin(elapsed * bobFrequency * (Mathf.PI * 2));
 
     
 
     // Steering
 
     rudder += Input.GetAxis("Horizontal") * rudderDelta * Time.deltaTime;
 
     if( rudder > maxRudder ){
 
         rudder = maxRudder;
 
     } else if ( rudder < -maxRudder ){
 
         rudder = -maxRudder;
 
     }



     heading = (heading + rudder * Time.deltaTime * signedSqrt(speed)) % 360;
 
     // transform.Rotate(0, rudder * Time.deltaTime, 0);
 
     transform.eulerAngles.y = heading;
 
     transform.eulerAngles.z = -rudder;
 
     
 
     if( rudderControl ){
 
         rudderAngle = ((-60 * rudder)/maxRudder + heading) % 360;
 
         //rudderControl.transform.localEulerAngles.y = (70 * rudderAngle) % 360;
 
         rudderControl.transform.eulerAngles = Vector3(0, rudderAngle, 0);
 
     }
 
     
 
     // Sail
 
     speed += Input.GetAxis("Vertical") * acceleration * Time.deltaTime;
 
     if( speed > maxspeed ){
 
         speed = maxspeed;
 
     } else if ( speed < minspeed ){
 
         speed = minspeed;
 
     }
 
     
 
     transform.Translate(0, 0, speed * Time.deltaTime);
 
 }
 
 
 
 function Awake (){
 
     seaLevel = transform.position.y;
 
     rudderControl = GameObject.Find("rudderControl");
 
 }


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 hexagonius · Sep 06, 2015 at 08:37 PM

Your models z axis points to the right. It's forward would be the negative x-Axis. In the Translate code, put the z value negated to the x value of the Translate parameters

Comment
Add comment · Show 3 · 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 panos12 · Sep 06, 2015 at 08:42 PM 0
Share

@hexagonius thanks for teh help unfortunately I cant understand what you are talking about I have little to no program$$anonymous$$g experience where I can change that if its in teh code can you quick fix it please?I would really appreciate it!

avatar image hexagonius · Sep 06, 2015 at 08:49 PM 0
Share

change line 115 to

 transform.Translate(-speed * Time.deltaTime,0,0);
avatar image panos12 · Sep 06, 2015 at 08:54 PM 0
Share

Thanks a lot!!!!!!!!!!!you saved my game lol!

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

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

Related Questions

Object reference not set to an instance of an object (c#) 0 Answers

How to define the forward direction of an object made in blender 1 Answer

How can I get all cameras enabled true false states ? 0 Answers

Does anyone know why transform.position isn't working? (See details) 1 Answer

How can i rotate all the child objects together at the same time ? 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