GuiCrossHair recognize the subject/item automatically

There are no stupid questions, just stupid answers.
  • 1
  • 2
15 posts Page 1 of 2
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
  by Bishop » Wed Mar 20, 2019 2:45 pm
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
irei1as
Posts: 84
Joined: Fri Feb 27, 2015 5:13 pm
by irei1as » Wed Mar 20, 2019 6:49 pm
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.
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Wed Mar 20, 2019 10:43 pm
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?
marauder2k9
Posts: 287
Joined: Wed Feb 18, 2015 7:36 am
by marauder2k9 » Thu Mar 21, 2019 12:57 am
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.
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Thu Mar 21, 2019 3:25 am
Thanks .... that would be great ...I think somehow improve that guicrosshair would be nice.... also Torque engine has trigger, zone, zoneportal, etc but RayCast build-in not.....it's a pity!
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Thu Mar 21, 2019 7:19 pm
I make it somehow together.....not exactly what I need....but works :)

Image

....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?
Duion
Posts: 1370
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Thu Mar 21, 2019 9:57 pm
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.
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Fri Mar 22, 2019 3:49 am
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.

Image
marauder2k9
Posts: 287
Joined: Wed Feb 18, 2015 7:36 am
by marauder2k9 » Fri Mar 22, 2019 11:16 pm
torque does have a cast ray feature built in through script, literally what u are doing is casting a ray on mouse click, u can do the same from the muzzle vector i think or it may be best from eye vector?
marauder2k9
Posts: 287
Joined: Wed Feb 18, 2015 7:36 am
by marauder2k9 » Fri Mar 22, 2019 11:21 pm
This script from the melee resource http://www.garagegames.com/community/re ... 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;

echo(%col);
//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");

echo(%col.getname());

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

%pushVec = VectorScale(%pushDirection,1000);
%pushVec= getwords(%pushVec,0,1);
%col.applyImpulse(%vpos, %pushVec);
}
}
  • 1
  • 2
15 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 2 guests