Jump to content

GuiCrossHair recognize the subject/item automatically


Recommended Posts

For my project I would need GuiCrossHair recognize the subject- interactive items automatically when the player points the crosshair on them and text about this item to appear on the screen.

.......what are the options in the Torque engine for this?

Thanks Bishop

Link to comment
Share on other sites

I think I would do:

1st. Tag the objects with a dynamic entry.

Something like: BoxObject13.checkData = "Ammo box";

Ah, make sure dynamic entries are set to save.

2nd. Make a function that takes the id of an object and writes in a guiText in the screen that checkData variable.

3rd. Make a ScriptTickObject that makes a raycast each frame to the cross position. If an object is found then use the function.

The bad of this approach is that its use of raycasts is kinda liberal... but I don't think it'll be much an issue if it's only once a frame.

If it's too bad I guess nobody will notice if it's every 5 frames or something. You could experiment.

Link to comment
Share on other sites

Thanks for help .....I try this points but I'm very begginer so a more detailed explanation would help me.

.....also there is no possibility mounted some object to the eye node and this object would make that raycasting to the objects/items?

Link to comment
Share on other sites

there was actually a resource that did this on the old forums that cast a ray to a set distance and checked if it was an object with a bool value checking to see if the object within the raycast had interact set to true. Once your able to do that its fairly straight forward to do the other stuff like setting up a listener for a key press and then doing the action required under the objects interaction. It did require some engine changes though. I think it was advanced crosshair or smart crosshair or something if i find it i will share the link.

Link to comment
Share on other sites

I make it somehow together.....not exactly what I need....but works :)


....I'm using PlayGui::onMouseDown(%this, %screenPos, %cameraPos, %worldDir) function......

....is there an option to display text when the cursor is over the subject and only in this time display the text?

Link to comment
Share on other sites

There are many pre-made functions like:

function PlayGui::onMouseUp(%this){ }

function PlayGui::onMouseDown(%this){ }

function PlayGui::onMouseMove(%this){ }

function PlayGui::onMouseDragged(%this){ }

function PlayGui::onMouseEnter(%this){ }

function PlayGui::onMouseLeave(%this){ }

What you want is on hover, but I don't know if that exists for this class, maybe try display it onMouseEnter and end display onMouseLeave, otherwise search the code for all functions that exist and try them until you get what you want.

Link to comment
Share on other sites

Thanks Duion, I used the build-in gui 3d model viewer and items text/name is now directly in the model viewer.....this 3d viewer is great for such stuff....thanks developers

who works on this....I still have to fine-tune a few things but I'm satisfied with the result....and of course, script manual and engine reference + docs are very useful.


Link to comment
Share on other sites

This script from the melee resource http://www.garagegames.com/community/resources/view/20273 creates a ray cast from the eye vector out a certain distance on melee attack u can modify this to be a function of its own to automatically check everything that the ray comes into contact with.

function CricketBatImage::Melee_Attack(%this, %obj)


%eyeVec = %obj.getEyeVector();

%startPos = %obj.getEyePoint();

%endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 2));

%target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);

%col = firstWord(%target);

if(%col == 0)



//return the ID of what we've hit

// Apply damage to the object all shape base objects

if (%col.getType() & $TypeMasks::ShapeBaseObjectType)


%col.damage(%obj, %pos, 15, "Cricket Bat Smack");


%vpos = %col.getWorldBoxCenter();

%pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());

%pushDirection = VectorNormalize(%pushDirection);

%pushVec = VectorScale(%pushDirection,1000);

%pushVec= getwords(%pushVec,0,1);

%col.applyImpulse(%vpos, %pushVec);



Link to comment
Share on other sites

Thanks marauder2k9....where to write that script .... to playGui.cs?.....I wrote it there but get unable to find object '821 493' attempting to call function 'getEyeVector' and same for 'getEyePoint'

....so that means this function can't find these objects? %eyeVec and %startPos....right?.....so I must write in that script function where to look for them?

Link to comment
Share on other sites

getEyeVector() and getEyePoint are in the ShapeBase Class .....so I need get

Player shape and his eye node....how to write this in the script?....I'm begginer to the Torque script.

EDIT: I get it.....$objID = my_player.getID();

echo("Object ID: " , $objID);........so I get my player capsule collision object and

there I have eye node as a child so %obj = $objID is this right?....so.... %obj.getEyePoint()...should find the eye node?


%obj = $objID.....this does not work....I got right ID from echo but Unknown command getEyeVector and getEyePoint.

Link to comment
Share on other sites

Bishop , I like what youre doing and appreciate you sharing the progress with it . In the editor select your player and get the ID number then , in the console type- IDnumber.geteyepoint() . If you get the answer you need the theres no problem with your player object . If you get an error then theres probably something wrong with the model / armature . The problem you mentioned could be in accessing the object ID with the function your using for the raycast . Id suggest making sure you are getting that ID number by just using an echo just before the get eyepoint or whatever method and check the result , you can also echo the eyevector etc... .

BTW I think youd set that $objectID at player onAdd . Then it change as you add respawned players .

Link to comment
Share on other sites

If you're in a single player environment (server=client) you can use the shortcuts

LocalClientConnection.player and LocaClientConnection.camera to get the id for the control player and camera.

Like: (LocalClientConnection.camera).getEyeVector();

But it's only for single player use. Do not use them if you eventually plan on going multiplayer.

Link to comment
Share on other sites

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...