• 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 CGFX360 · Feb 23, 2014 at 05:22 AM · controllersystemcontrolship

Sailing Ship Control Script Help

I have been playing with a script i found here on the unity forums that is for controlling a ship.

Found Here: http://forum.unity3d.com/threads/2278-Sailing-Ship-Control

I was able to make one adjustment i needed, which was very simple, just removing a small snip of code.

But there are some more adjustment's i need, and i have no idea how to do it, i've tried everything i could think of but no luck.

I need two things

  1. When you stop pushing the "Horizontal" input, i want it to stop turning the ship, instead of continuing to turn.

  2. I want it so when you push the "Vertical" input (just once, no need to hold the button down), it slowly increases the speed to max speed, and pushing it opposite to the way the ship is moving (so if the ship is going forward, pressing "S"), will stop the ship/move the ship backwards.

How would this be accomplished?

Sorry, I'm kinda a noob with this stuff, i am still learning =/

Here's 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;
  
 private var startPosition : Vector3;
  
  
  
 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.GetAxisRaw("Horizontal") * rudderDelta * Time.deltaTime;
  
  
     if( rudder > maxRudder ){
  
         rudder = maxRudder;
  
     } else if ( rudder < -maxRudder ){
  
         rudder = -maxRudder;
  
     }
  
     heading = (heading + rudder * Time.deltaTime) % 360;
  
     // transform.Rotate(0, rudder * Time.deltaTime, 0);
  
     transform.eulerAngles.y = heading;
  
     transform.eulerAngles.z = -rudder;
    
  
    
    
  
     // 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 · Show 1
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 StonedLover · Jul 15, 2017 at 07:34 AM 0
Share

Is there still a need for the vertical move stop part?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by StonedLover · Jul 14, 2017 at 06:09 PM

         if (Input.GetAxisRaw("Horizontal") != 0)
             rudder += Input.GetAxisRaw("Horizontal") * rudderDelta * Time.deltaTime;
         else if (rudder >= 0 && Input.GetAxisRaw("Horizontal") == 0)
             rudder -= rudderDelta * Time.deltaTime;
         else if (rudder <= 0&& Input.GetAxisRaw("Horizontal") == 0)
             rudder += rudderDelta * Time.deltaTime;
 

Thats how you do the stopping

yeah lil bit late but maybe someone need it

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

21 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to make camera position relative to a specific target. 1 Answer

Joystick isn't responding? 0 Answers

Camera Shaking At High Speed 1 Answer

Setting Scroll View Width GUILayout 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges