Guest User

Untitled

a guest
Oct 16th, 2019
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HoverBikeScript : MonoBehaviour
  6. {
  7. RaycastHit hit;
  8. public Rigidbody hoverbike;
  9. readonly float yForce = 20;
  10. public Transform target;
  11. public float force = 0.1f;
  12. // Start is called before the first frame update
  13.  
  14.  
  15.  
  16. // Update is called once per frame
  17. private void Update()
  18. {
  19.  
  20. Physics.Raycast(hoverbike.transform.position, Vector3.down, out hit);
  21. Debug.Log(hit.distance);
  22. Debug.Log(yForce);
  23. if (hit.distance < 10)
  24. {
  25. if (hoverbike.velocity.y < 0)
  26. {
  27. hoverbike.AddForce(0, yForce, 0, ForceMode.Acceleration);
  28. }
  29. }
  30. if (Input.GetKey(KeyCode.S))
  31. {
  32. var camForward = Camera.main.transform.forward;
  33. hoverbike.AddForce((camForward * -15), ForceMode.Acceleration);
  34. }
  35. if (Input.GetKey(KeyCode.W))
  36. {
  37. var camForward = Camera.main.transform.forward;
  38. hoverbike.AddForce(camForward * 15, ForceMode.Acceleration);
  39. }
  40. if (hoverbike.velocity.x != 0 || hoverbike.velocity.z != 0)
  41. {
  42. if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.W))
  43. {
  44. //do nothing
  45. }
  46. else
  47. {
  48. 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)));
  49. }
  50.  
  51. }
  52. if (hoverbike.rotation.x != 0 || hoverbike.rotation.z != 0)
  53. {
  54. //hoverbike.MoveRotation(Quaternion.Euler(x: Mathf.MoveTowardsAngle(hoverbike.rotation.x, 0, 0.1f) , y: hoverbike.rotation.y, z: hoverbike.rotation.z));
  55. hoverbike.AddTorque(x: Mathf.MoveTowardsAngle(hoverbike.rotation.x, 0, 0.01f), y: hoverbike.rotation.y, z: Mathf.MoveTowardsAngle(hoverbike.rotation.z, 0, 0.01f));
  56. }
  57.  
  58. transform.Rotate(0.0f, -Input.GetAxis("Mouse X") * 0.5f, 0.0f);
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment