Hi, I'm making a game where you can pick up and move objects when an object is placed in front of them. This object has a raycast attached which enables the movement script when it finds a moveable object. However, the Ray travels forwards in terms of game position, which means when you play the game, you actually have to be slightly left or right of the object for the ray to hit, which isnt very intuitive.
So basically, I want to shoot a ray forward from the object whilst moving forward in terms of the screen position. It needs to start from the object, not the camera.
I think I can do this with Camera.WorldToScreenPoint, but, being completely honest, after trying several different ways, I figured I honestly have no idea how to use that code. Can anyone help me figure it out?
Here's the Raycasting portions of my script, although it's pretty standard:
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
//Defining the travel direction of the raycast vector
var hit : RaycastHit;
//If Raycast collides with something, that becomes the 'hit'
//var illuminate : RaycastHit;
var LayerMask = 1 << 9;
//Interacts with 1 layer - Layer 9 - Moveable
//Draws ray vector in Scene view
Debug.DrawRay(transform.position, fwd * 50, Color.green);
(Physics.Raycast (transform.position, fwd, hit, 50, LayerMask));