lxFirebal69xl Posted March 17, 2016 Share Posted March 17, 2016 I was looking to create a specific segment for my game that had a trigger happen when the player looked at something (it could be a model or a pivot, either would work). Thing is how would this be possible? Since we're talking about the player's vision and not collision I have no idea how to even start doing this. Here's an example, where you see the player running around everywhere, but only when he looks in a specific direction (in this case, up) does something happen. Quote Link to comment Share on other sites More sharing options...
thehankinator Posted March 17, 2016 Share Posted March 17, 2016 Stupid back button, lost everything. The easiest way would be to create a trigger zone with a script that takes an entity as a property (this is the object you are checking for, don't use a pivot) do a world:pick from the camera to a point some distance in front of the camera and check if it is the object you are looking for. Disclaimer: I didn't even try to run this code so there could be syntax/logical errors but the concept should work. Script.object = nil --entity function Script:Collision(entity, position, normal, speed) --todo add guards to ensure we only try this with the player local p0 = entity:GetPosition(true) local p1 = Transform:Point(0,0,20,entity.script.camera,nil)--change 20 to whatever max distance you want it to trigger with local pickInfo = PickInfo() if world:Pick(p0, p1, pickInfo, 0, true, Collision.LineOfSight) then if pickInfo.entity == self.object then --do something scary --hide to prevent triggering twice end end end Another way: Get the difference between the camera's position and the object, get the rotation of the camera then get the dot product(Vec3:Dot()) of the two. Might get awkward but you could use a pivot. Quote Link to comment Share on other sites More sharing options...
Rick Posted March 17, 2016 Share Posted March 17, 2016 As hank said use a pick, but you can also pick from the camera itself (where the mouse position is the center of the screen). No need for that specific example to use the world and Transform:Point(). Same idea, just an alternative way to do it. http://www.leadwerks.com/werkspace/page/api-reference/_/camera/camerapick-r199 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted March 18, 2016 Share Posted March 18, 2016 Use the Draw() script function, together with a distance check maybe. Quote My job is to make tools you love, with the features you want, and performance you can't live without. 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.
Note: Your post will require moderator approval before it will be visible.