Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class HoverBikeScript : MonoBehaviour
- {
- RaycastHit hit;
- public Rigidbody hoverbike;
- readonly float yForce = 20;
- public Transform target;
- public float force = 0.1f;
- // Start is called before the first frame update
- // Update is called once per frame
- private void Update()
- {
- Physics.Raycast(hoverbike.transform.position, Vector3.down, out hit);
- Debug.Log(hit.distance);
- Debug.Log(yForce);
- if (hit.distance < 10)
- {
- if (hoverbike.velocity.y < 0)
- {
- hoverbike.AddForce(0, yForce, 0, ForceMode.Acceleration);
- }
- }
- if (Input.GetKey(KeyCode.S))
- {
- var camForward = Camera.main.transform.forward;
- hoverbike.AddForce((camForward * -15), ForceMode.Acceleration);
- }
- if (Input.GetKey(KeyCode.W))
- {
- var camForward = Camera.main.transform.forward;
- hoverbike.AddForce(camForward * 15, ForceMode.Acceleration);
- }
- if (hoverbike.velocity.x != 0 || hoverbike.velocity.z != 0)
- {
- if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.W))
- {
- //do nothing
- }
- else
- {
- hoverbike.AddForce(new Vector3(x: -Mathf.MoveTowards(hoverbike.velocity.x, 0, 0.1f), y: hoverbike.velocity.y, z: -Mathf.MoveTowards(hoverbike.velocity.z, 0, 0.1f)));
- }
- }
- if (hoverbike.rotation.x != 0 || hoverbike.rotation.z != 0)
- {
- //hoverbike.MoveRotation(Quaternion.Euler(x: Mathf.MoveTowardsAngle(hoverbike.rotation.x, 0, 0.1f) , y: hoverbike.rotation.y, z: hoverbike.rotation.z));
- hoverbike.AddTorque(x: Mathf.MoveTowardsAngle(hoverbike.rotation.x, 0, 0.01f), y: hoverbike.rotation.y, z: Mathf.MoveTowardsAngle(hoverbike.rotation.z, 0, 0.01f));
- }
- transform.Rotate(0.0f, -Input.GetAxis("Mouse X") * 0.5f, 0.0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment