Need disk to follow mouse

k, i understand that the mouse cursor doesnt exist in 3d but is there a simple way to tell an object to move towards the mouse cursor, basicly want i want to do is have my character throw her disk weapon forward but have the disk track the mouse cursor in a limited fashion. If anyone has played the newest AvP game and is fimilure with the preditors smart disk then basicly i want to do that.

whats your camera setup? Use the hit.point as your 3D-coordinate, or just use the x and z coordinate and set y(height) manually

using the third person camera prefab. My HUD GUI script draws a crosshair textrure to the mouse’s position on the screen, just wondering whats the easiest way to get objects to auto steer towards where the reticle is pointing.

so to get PointToRay to work on mouse x and y would it look something like this.

function Update () {
var ray : Ray = camera.ScreenPointToRay (Vector3(Input.mousePosition.x,Input.mousePosition.y - Screen.height,0));
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
}

not sure, i use c# all the time.

i use rightclick-panning for my homing-missile test of my game

the code to get the position of the mouse in the scene:

Vector3 pos = cam.ScreenPointToRay(Input.mousePosition).GetPoint(30);
//GetPoint(30): cameraheight = 30, so the point will be 30m away from the camera if i remember that right

function Update () {
var ray : Ray = camera.ScreenPointToRay (Vector3(Input.mousePosition.x,Input.mousePosition .y - Screen.height,0));
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 10)) {
print (“There is something in front of the object!”);
}
}

this is what i have so far and it seems to be working as its returning a “There is something in front of …” message in the debug. so how can i take the xyz of where its hitting and transfer that to something the disk can home in one?

Quick question. Why are you subtracting the Screen.height from Input.mousePosition.y? Wouldnt that jsut make it off the screen?

In order to make your raycast work, you should look at the documentation for the Raycast.

You will see that you can use a RaycastHit in there. This hit gives you the point, normal objects and so forth about the hit. The hit.point is where the raycast hit.

subtracting screen height is only way i can get the target reticle to move correctly on the y axis, some odd ball reason the mouse y behaves defferently, if you did just input.mousepositon.y what ever is following the mouse on that axis will move counter to where u move the mouse. idk but scripwise this is what i read to do.

i changed the code so the raytrace origonates from the center of the crosshair image instead of the mouse position. seems to work so hopefully where ever the dead center of the target image is were the disk will go.

code for object that creates disk and gives it velocity…

public var disk:Rigidbody;
var aim;
function Update () {
if (Input.GetMouseButtonDown(0)) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Rigidbody;
aim = GetComponent(HUD).aiming.position;
clone = Instantiate(disk, transform.position, transform.rotation);
clone.velocity = Vector3.MoveTowards(transform.position,aim, 1);
}
}

code for raycast…

public var aiming:RaycastHit;

function Update () {
var ray : Ray = camera.ScreenPointToRay (Vector3(target.width / 2,target.height / 2,0));
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 10)) {
print (“There is something in front of the object!”);
}
}

hoping someone can figure out what i did wrong cause now my disk object doesnt even appear. i cant tell if this is working or not. what im trying to do is assign the location value of where the raycast hits to the variable the disk uses to home in on.

i found a simpler idea, im gona replace the disk with a gun and use the unity code example that creates particles on raycasthit.