123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RbMovement : MonoBehaviour
- {
- private Transform t;
- public Transform bottom;
- private Rigidbody rb;
- // Start is called before the first frame update
- private float speedIncreasePerSecond = 2f;
- private float leanIncreasePerSecond = 10f;
- private float steerIncreasePerSecond = 15f;
- private float speed;
- private float lean;
- private float steer;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- t = transform;
- }
- private void Update()
- {
- if (Input.GetKey(KeyCode.W))
- {
- speed += speedIncreasePerSecond * Time.deltaTime;
- }
- else if (Input.GetKeyUp(KeyCode.W))
- {
- speed = 0;
- }
- if (Input.GetKey(KeyCode.S))
- {
- speed -= speedIncreasePerSecond * Time.deltaTime;
- }
- else if (Input.GetKeyUp(KeyCode.S))
- {
- speed = 0;
- }
- if (Input.GetKey(KeyCode.A))
- {
- steer += steerIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.D))
- {
- steer -= steerIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
- {
- steer = 0;
- }
- if (Input.GetKey(KeyCode.Q))
- {
- lean -= leanIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKey(KeyCode.E))
- {
- lean += leanIncreasePerSecond * Time.deltaTime;
- }
- if (Input.GetKeyUp(KeyCode.Q) || Input.GetKeyUp(KeyCode.E))
- {
- lean = 0f;
- }
- }
- // Update is called once per frame
- void FixedUpdate()
- {
- t.RotateAround(t.position, t.up, steer);
- t.RotateAround(bottom.position, t.forward, lean);
- rb.MovePosition(rb.position + t.forward * (Time.deltaTime * speed));
- }
- }
|