Author Topic: Getting an objects id by looking at it.  (Read 765 times)

I am needing this for a little project I am working on that I might release if people likes the idea.

Anyway to make it short I just a command to get the ID of an object that the players aiming at, like the /getid command.

I know it has something to do with raycasts and crap which I was never good at it.

Code: [Select]
%target = containerRayCast(%cl.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%cl.player.getEyeVector()), 5), %cl.player.getEyePoint()), $typeMasks::playerObjectType).client;
This gets the client that a player is looking at.

just replace .client; with .getid();

Thanks I will try that out.

Code: [Select]
%target = containerRayCast(%cl.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%cl.player.getEyeVector()), 5), %cl.player.getEyePoint()), $typeMasks::playerObjectType).client;
This gets the client that a player is looking at.

just replace .client; with .getid();
on a related note, so i'm not posting a whole new topic, is there a way to get the direction in x y z of a player's looking? so that i could add velocity to a vehicle in that direction?

on a related note, so i'm not posting a whole new topic, is there a way to get the direction in x y z of a player's looking? so that i could add velocity to a vehicle in that direction?
player.getEyeVector()

Code: [Select]
%target = containerRayCast(%cl.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%cl.player.getEyeVector()), 5), %cl.player.getEyePoint()), $typeMasks::playerObjectType).client;
This gets the client that a player is looking at.

just replace .client; with .getid();

I tried it and it keeps getting my id not what i am looking at

I tried it and it keeps getting my id not what i am looking at
Code: [Select]
%start = %player.getEyePoint();
%end = vectorAdd(%start,vectorScale(%player.getEyeVector(),15));
%ray = containerRayCast(%start,%end,$TypeMasks::All,%player);
%col = firstWord(%ray);
« Last Edit: July 17, 2011, 10:13:44 PM by Destiny/Zack0Wack0 »

I tried it and it keeps getting my id not what i am looking at
just replace .client; with .getid();

Warning - while you were reading a new reply has been posted. You may wish to review your post.

oh

Code: [Select]
%ray = containerRayCast(%player.getEyePoint(),vectorScale(%player.getEyeVector(),5),$TypeMasks::All,%player);
%col = firstWord(%ray);
Thank you.
Edit
It doesnt aim accuratly
« Last Edit: July 17, 2011, 10:08:40 PM by Pah1023 »

Woops, sorry.
Code: [Select]
%start = %player.getEyePoint();
%end = vectorAdd(%start,vectorScale(%player.getEyeVector(),15));
%ray = containerRayCast(%start,%end,$TypeMasks::All,%player);
%col = firstWord(%ray);

Woops, sorry.
Code: [Select]
%start = %player.getEyePoint();
%end = vectorAdd(%start,vectorScale(%player.getEyeVector(),15));
%ray = containerRayCast(%start,%end,$TypeMasks::All,%player);
%col = firstWord(%ray);
Thanks alot, I appreciate it.

player.getEyeVector()
i'm looking at this and when i look straight up one of the numbers comes out in ten millions. is there a way of reducing it so it doesn't do something like this? since i'm planning on using this on a vehicle that really wouldn't work.

i'm looking at this and when i look straight up one of the numbers comes out in ten millions. is there a way of reducing it so it doesn't do something like this? since i'm planning on using this on a vehicle that really wouldn't work.
It's to the power e-006 - meaning that if you multiplied it by 10^-6 (which would make it one million times smaller) that would be the value. Player.getEyeVector() will always be a normalized vector (meaning the length, or if you're going to use it for velocity, speed) will be 1.