- Home /
 
Unity Rotate Raycast on Quaternion
Hi, sorry, I am still a beginner, but I need some help.
I want my player to have a raycast for my flashlight, and when this ray hits the enemy, I want it to slow the enemy down. I want the raycast rotation to be player.transform.rotation, but that variable is a Quaternion, and the field in the raycast requires a Vector 3, how can I rotate the raycast with a quaternion smoothly?
BTW this script is attached to the enemy.
 public class MogiAI : MonoBehaviour {
 
     public GameObject player;
 
     public GameObject flashlight;
     
     public float MovementSpeed = 2;
 
     public bool IsMoving = false;
 
     bool Triggered = false;
 
     private healthscript healthy;
 
     // Use this for initialization
     void Start () {
         healthy = player.GetComponent<healthscript>();
     }
     
     // Update is called once per frame
     void Update () {
         RaycastHit hit;
         Ray lighter = new Ray (flashlight.transform.position, flashlight.transform.rotation);
 
         if (Physics.Raycast (lighter, out hit, 10.0f)) {
             Debug.Log ("finally");
                 }
         if (player.transform.position.y < 8.4) {
                         IsMoving = true;
                 } else {
             IsMoving = false;
                 }
         if (IsMoving == true){
             transform.position = Vector3.MoveTowards (transform.position, player.transform.position, MovementSpeed * Time.deltaTime);
         }
         transform.LookAt (player.transform.position);
         if (Triggered == true) {
             healthy.health = healthy.health - 0.5f;
                 }
     }
 
     void OnTriggerEnter (){
         Triggered = true;
     }
 
     void OnTriggerExit (){
         Triggered = false;
     }
 
 }
 
 
              Answer by TVG33K · Jul 05, 2017 at 08:34 PM
Sorry, I found out the way to do it on my own. I put a raycast script on the player and did it all in reverse! It turns out you cant put a raycast and rotate it properly on another object.
Your answer
 
             Follow this Question
Related Questions
Have An Object Rotate Around Transform A So That Transform B is Looking at Transform C (C#) 0 Answers
Make a side of an object LookAT another object 1 Answer
How to smoothly rotate to certain directions using input axis 1 Answer
Object slope rotation issue 0 Answers
c# modify only one axis of a quaternion 2 Answers