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;
}
}