Help Converting Raycast Into a Raycast2D
I have a script that detects the floor through a raycast, but it's 3d and I do not know how to convert it to 2d, here's the script:
using UnityEngine; public class SlopeDetectionScript : MonoBehaviour { RaycastHit hit; Quaternion rot; public int smooth; public float length; void Update() { Ray ray = new Ray(transform.position, -transform.up); if (Physics.Raycast (ray, out hit,length)) { rot = Quaternion.FromToRotation (transform.up, hit.normal) * transform.rotation; transform.rotation = Quaternion.Lerp (transform.rotation, rot, Time.deltaTime * smooth); } else { transform.rotation = Quaternion.Euler(Quaternion.identity.x,transform.eulerAngles.y,Quaternion.identity.z); } } }
but the player has to shoot the raycast from his rotation to down
Your answer
Follow this Question
Related Questions
Raycast is hitting enemy even when not in contact with it? 2 Answers
CircleCast hit its origin... 0 Answers
Raycast 2d don't work 0 Answers
Basic AI avoidance in 2D 1 Answer
Problem with raycasting towards mouse 0 Answers