Page 1 of 1

understanding get_look_dir()

PostPosted: Fri Dec 12, 2014 21:10
by LocaL_ALchemisT
how can it get camera direction as a unit vector? any equations, formulas?

does it have to do with player's position and pointed thing's position?

Re: understanding get_look_dir()

PostPosted: Fri Dec 12, 2014 21:20
by Krock
Could be helpful:

https://github.com/stujones11/shooter/b ... #L253-L262
It spawns a particle (the shot) with a speed, calculated by the looking direction.

Re: understanding get_look_dir()

PostPosted: Fri Dec 12, 2014 21:40
by kaeza
The value returned by `get_look_dir` is an unit vector representing the camera direction.

Re: understanding get_look_dir()

PostPosted: Fri Dec 12, 2014 22:17
by LocaL_ALchemisT
my objective is actually to make an entity perform action when it is inside a player's view, the entity does not have to be pointed by the player.

i ithought that by using the player's coord, the entity's coord and get_look_dir() i can achieve this kind of action.

Re: understanding get_look_dir()

PostPosted: Sat Dec 13, 2014 15:54
by ArguablySane
I don't know if there's a way to get the player's field of view, but you can certainly make the entity detect when the player is looking near it.

Calculate the vector between the player and the object.
Find the angle between that vector and the view direction vector for the player.
If the angle is less than some value, assume that the player can see it.

To find the angle, use the dot product.

Re: understanding get_look_dir()

PostPosted: Sun Dec 14, 2014 00:21
by LocaL_ALchemisT
thank you very much!

Re: understanding get_look_dir()

PostPosted: Tue Dec 16, 2014 18:51
by Hybrid Dog
Can I somehow get the exact pointed position instead of the position of the node, which is pointed? I think the paintings mod does this, but when l read its code a few months ago, l didn't know scalar products (or dot products?) yet, which might be necessary for this.

Re: understanding get_look_dir()

PostPosted: Tue Dec 16, 2014 23:02
by ArguablySane
Hybrid Dog wrote:Can I somehow get the exact pointed position instead of the position of the node, which is pointed? I think the paintings mod does this, but when l read its code a few months ago, l didn't know scalar products (or dot products?) yet, which might be necessary for this.


I don't think there's any built-in function to do this, but I could be wrong.

To do it manually, you need to look up how to find the intersection between a vector and a plane. Then you assume that the looked-at node is a cube and calculate intersections with all 6 faces. The exact pointed position is the intersection point closest to the player which doesn't lie outside the cube. It's a bit tricky, but mostly just involves lots of vector algebra.

If you want to work with non-cubic nodes, then the entire thing gets a lot more complicated and I wouldn't even know where to begin.

Re: understanding get_look_dir()

PostPosted: Wed Dec 17, 2014 14:00
by Hybrid Dog
ArguablySane wrote:
Hybrid Dog wrote:Can I somehow get the exact pointed position instead of the position of the node, which is pointed? I think the paintings mod does this, but when l read its code a few months ago, l didn't know scalar products (or dot products?) yet, which might be necessary for this.


I don't think there's any built-in function to do this, but I could be wrong.

To do it manually, you need to look up how to find the intersection between a vector and a plane. Then you assume that the looked-at node is a cube and calculate intersections with all 6 faces. The exact pointed position is the intersection point closest to the player which doesn't lie outside the cube. It's a bit tricky, but mostly just involves lots of vector algebra.

If you want to work with non-cubic nodes, then the entire thing gets a lot more complicated and I wouldn't even know where to begin.

thanks, l don't need to find the closest of the intersection points because on_punch offers pointed_thing, which contains the pointed node's position and the position where a node would be placed