I’m trying to figure out how to make it so a raycast with the max length of 10 (A test number) to come off of my player, rotate with it, and so on. I know how to have a ray created from my click position and my camera, but how could I go about this with my character and with the E key.
In the documentation the first example is exactly what you want. Unity - Scripting API: Physics.Raycast
with a little modification:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public float rayDistance = 10.0f;
void Update() {
if(Input.GetKeyDown(KeyCode.E))
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, rayDistance))
print("There is something in front of the object!");
}
}
}
Just put this script to you player. You can change the rayDistance in the inspector too and you can change the direction from forward to mouse position if you want.