Advertisement
jemmm

exr09

Dec 5th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7. public float speed = 2;
  8.  
  9. Rigidbody rb;
  10.  
  11. public float targetangle = 10;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. rb = GetComponent<Rigidbody>();
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update()
  20. {
  21.  
  22. Debug.DrawRay(transform.position, transform.forward * 3, Color.red);
  23.  
  24.  
  25.  
  26. RaycastHit hit;
  27.  
  28. if (Physics.Raycast(transform.position, transform.forward, out hit, 3f))
  29. {
  30. print(hit.collider.name);
  31.  
  32. if (hit.collider.tag == "Wall")
  33. {
  34. //transform.Rotate(0, 90, 0);
  35.  
  36. rb.velocity = Vector3.zero;
  37.  
  38. float w = transform.rotation.eulerAngles.y;
  39.  
  40. int d = Random.Range(1, 3);
  41.  
  42.  
  43. w += d == 1 ? 90 : -90;
  44.  
  45. //if (d == 1)
  46. //{
  47.  
  48. //w += 90;
  49.  
  50. //}
  51. //else
  52. //{
  53. //w -= 90;
  54. //}
  55.  
  56. Quaternion target = Quaternion.AngleAxis(w, Vector3.up);
  57.  
  58. transform.rotation = target;
  59. }
  60. //float x = transform.rotation.eulerAngles.x;
  61. //float y = transform.rotation.eulerAngles.y;
  62. //float z = transform.rotation.eulerAngles.z;
  63. //Vector3 angle = new Vector3(x, y + targetangle, z);
  64. //rb.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.EulerAngles(angle), targetangle * Time.deltaTime);
  65. }
  66. else
  67. {
  68. rb.AddRelativeForce(Vector3.forward * speed);
  69.  
  70. }
  71.  
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement