Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public float speed = 2;
- Rigidbody rb;
- public float targetangle = 10;
- // Start is called before the first frame update
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- Debug.DrawRay(transform.position, transform.forward * 3, Color.red);
- RaycastHit hit;
- if (Physics.Raycast(transform.position, transform.forward, out hit, 3f))
- {
- print(hit.collider.name);
- if (hit.collider.tag == "Wall")
- {
- //transform.Rotate(0, 90, 0);
- rb.velocity = Vector3.zero;
- float w = transform.rotation.eulerAngles.y;
- int d = Random.Range(1, 3);
- w += d == 1 ? 90 : -90;
- //if (d == 1)
- //{
- //w += 90;
- //}
- //else
- //{
- //w -= 90;
- //}
- Quaternion target = Quaternion.AngleAxis(w, Vector3.up);
- transform.rotation = target;
- }
- //float x = transform.rotation.eulerAngles.x;
- //float y = transform.rotation.eulerAngles.y;
- //float z = transform.rotation.eulerAngles.z;
- //Vector3 angle = new Vector3(x, y + targetangle, z);
- //rb.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.EulerAngles(angle), targetangle * Time.deltaTime);
- }
- else
- {
- rb.AddRelativeForce(Vector3.forward * speed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement