Jump to content
Unity Insider Forum
Sign in to follow this  
scowo

ShipDrive

Recommended Posts

Hi Leute hab mal gestern angefangen zu schrieben und zwar ein Ship drive Control. Bei mir hats supergeklappt und da wollte ich euch das Script zeigen vlt braucht das wer

 

 

   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 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;
    }
    if( rudderControl ){
	    rudderAngle = rudder / maxRudder;
	    rudderControl.transform.localEulerAngles.y = (70 * rudderAngle) % 360;
    }
    heading = (heading + rudder * Time.deltaTime * Mathf.Sqrt(speed)) % 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");
   }

 

Viel Spass damit :D

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×