Bishop Posted March 20, 2019 Share Posted March 20, 2019 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 Quote Link to comment Share on other sites More sharing options...
irei1as Posted March 20, 2019 Share Posted March 20, 2019 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. Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 20, 2019 Author Share Posted March 20, 2019 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? Quote Link to comment Share on other sites More sharing options...
marauder2k9 Posted March 20, 2019 Share Posted March 20, 2019 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. Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 21, 2019 Author Share Posted March 21, 2019 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! Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 21, 2019 Author Share Posted March 21, 2019 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? Quote Link to comment Share on other sites More sharing options...
Duion Posted March 21, 2019 Share Posted March 21, 2019 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. Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 22, 2019 Author Share Posted March 22, 2019 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 developerswho 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. Quote Link to comment Share on other sites More sharing options...
marauder2k9 Posted March 22, 2019 Share Posted March 22, 2019 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? Quote Link to comment Share on other sites More sharing options...
marauder2k9 Posted March 22, 2019 Share Posted March 22, 2019 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; 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); }} Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 23, 2019 Author Share Posted March 23, 2019 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? Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 23, 2019 Author Share Posted March 23, 2019 getEyeVector() and getEyePoint are in the ShapeBase Class .....so I need getPlayer 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 andthere I have eye node as a child so %obj = $objID is this right?....so.... %obj.getEyePoint()...should find the eye node?EDIT1:%obj = $objID.....this does not work....I got right ID from echo but Unknown command getEyeVector and getEyePoint. Quote Link to comment Share on other sites More sharing options...
fLUnKnhaXYU Posted March 23, 2019 Share Posted March 23, 2019 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 . Quote Link to comment Share on other sites More sharing options...
irei1as Posted March 24, 2019 Share Posted March 24, 2019 If you're in a single player environment (server=client) you can use the shortcutsLocalClientConnection.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. Quote Link to comment Share on other sites More sharing options...
Bishop Posted March 24, 2019 Author Share Posted March 24, 2019 Thanks very much for help guys....I appreciate that.Yes definitely singleplayer....this project it'll be a exploration walking....first person only...with somepuzzles...blog about is here http://forums.torque3d.org/viewtopic.php?f=8&t=1542....so I get it working by mouse cursor...and the trick I used is that RMB is set to display the mouse cursor...so the screen responds only to the mouse cursor and camera does not move... the player must now hold the RMB pressed....when player release RMB then mouse cursor is hidden and cursoris off....and when cursor is hidden I set his position to the middle of the screen ( where is crosshair ) so when player pressed LMB....hidden mouse cursor raycasting items/objects in the scene so this looks like crosshair do raycasting :) ....and at that moment the 3d model viewer appears with clickeditem/object to explore in detail.....then when player clicks again with LMB but only outside of the model/item in the scene, 3dmodel viewer disappears and when RMB is pressed inside or outsideof the model/item and 3d model viewer is just on the screen and player don't want to explore anything in the 3d viewer....so it disappears.This works really well and the advantage is that the cursor is available on RMB click for use on other things......but i'll try the crosshair raycasting solution but with thisI I'm quite satisfied...... I will post later a gif where it will be better to see in action. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.