Jump to content

Recommended Posts

Posted

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.

Posted

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.

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.

Guest
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...