Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class RuchYacht : MonoBehaviour {
- //zmienne wyswietlane
- public float maxSpeed;
- public float speed = 0;
- public float UstawieniePletwy;
- public float predObrot;
- //Nomoto
- float wychylenie_pletwy;
- float pletwa_sigmaR = 0;
- float T = 50.66F;
- float K = 0.007F;
- float sigmaC = -0.0159F;
- float rot = 0;
- float cog;
- //zmienne pozycji poczatkowej
- float z;
- float x;
- public Slider SliderPredkosc;
- public Slider SliderPletwy;
- public Button btnZerujPred;
- // Use this for initialization
- void Start()
- {
- x = transform.position.x;
- z = transform.position.z;
- cog = transform.eulerAngles.y;
- }
- // Update is called once per frame
- void FixedUpdate ()
- {
- maxSpeed = SliderPredkosc.value;
- UstawieniePletwy = SliderPletwy.value;
- // PREDKOSC
- btnZerujPred.onClick.AddListener(TaskOnClick);
- pletwa_sigmaR = Mathf.MoveTowards(pletwa_sigmaR, SliderPletwy.value, 0.5F * Time.deltaTime * 5);
- speed = Mathf.MoveTowards(speed, SliderPredkosc.value, 1.0F * Time.deltaTime * 5);
- rot += K * (sigmaC + pletwa_sigmaR) - rot * Time.deltaTime / T;
- cog += rot * Time.deltaTime;
- x += speed * Time.deltaTime * cos(cog);
- z += speed * Time.deltaTime * sin(cog);
- predObrot = cog;
- transform.position = new Vector3(x, transform.position.y, z);
- transform.rotation = Quaternion.Euler(0, cog, 0);
- }
- private float sin (float alfa) { return Mathf.Sin(alfa * Mathf.PI / 180); }
- private float cos (float alfa) { return Mathf.Cos(alfa * Mathf.PI / 180); }
- void TaskOnClick() //polecenie zerowania predkosci
- {
- SliderPredkosc.value = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement