Vehicle: Boat accelerating and turning in Unity

Posted by Emilios S. on Game Development See other posts from Game Development or by Emilios S.
Published on 2014-08-21T20:38:41Z Indexed on 2014/08/21 22:28 UTC
Read the original article Hit count: 397

Filed under:
|
|
|

I'm trying to make a player-controllable boat in Unity and I'm running into problems with my code.

1) I want to make the boat to accelerate and decelerate steadily instead of simply moving the speed I'm telling it to right away.

2) I want to make the player unable to steer the boat unless it is moving.

3) If possible, I want to simulate the vertical floating of a boat during its movement (it going up and down)

My current code (C#) is this:

using UnityEngine;
using System.Collections;

public class VehicleScript : MonoBehaviour {
public float speed=10; 
public float rotationspeed=50;

// Use this for initialization
// Update is called once per frame
void Update () {

    // Forward movement
    if(Input.GetKey(KeyCode.I))
    speed = 
    transform.Translate (Vector3.left*speed*Time.deltaTime);

    // Backward movement
    if(Input.GetKey(KeyCode.K))
        transform.Translate (Vector3.right*speed*Time.deltaTime);

    // Left movement
    if(Input.GetKey(KeyCode.J))
        transform.Rotate (Vector3.down*rotationspeed*Time.deltaTime);

    // Right movement
    if(Input.GetKey(KeyCode.L))
        transform.Rotate (Vector3.up*rotationspeed*Time.deltaTime);

}
}

In the current state of my code, when I press the specified keys, the boat simply moves 10 units/sec instantly, and also stops instantly. I'm not really sure how to make the things stated above, so any help would be appreciated. Just to clarify, I don't necessarily need the full code to implement those features, I just want to know what functions to use in order to achieve the desired effects.

Thank you very much.

© Game Development or respective owner

Related posts about c#

Related posts about unity