understanding get_look_dir()

User avatar
LocaL_ALchemisT
Member
 
Posts: 56
Joined: Thu Jul 19, 2012 16:21
Location: Asia Tenggara

understanding get_look_dir()

by LocaL_ALchemisT » Fri Dec 12, 2014 21:10

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?
Built Telegate v1.0, Workers v2.0, Broadcast v0.0 & Weeping Angel v0.1
Having A Buzy Week
From 0.4.10 with love~
 

User avatar
Krock
Developer
 
Posts: 4469
Joined: Thu Oct 03, 2013 07:48
Location: Switzerland
GitHub: SmallJoker

Re: understanding get_look_dir()

by Krock » Fri Dec 12, 2014 21:20

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.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
 

User avatar
kaeza
Moderator
 
Posts: 2162
Joined: Thu Oct 18, 2012 05:00
Location: Montevideo, Uruguay
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

Re: understanding get_look_dir()

by kaeza » Fri Dec 12, 2014 21:40

The value returned by `get_look_dir` is an unit vector representing the camera direction.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal
 

User avatar
LocaL_ALchemisT
Member
 
Posts: 56
Joined: Thu Jul 19, 2012 16:21
Location: Asia Tenggara

Re: understanding get_look_dir()

by LocaL_ALchemisT » Fri Dec 12, 2014 22:17

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.
Built Telegate v1.0, Workers v2.0, Broadcast v0.0 & Weeping Angel v0.1
Having A Buzy Week
From 0.4.10 with love~
 

User avatar
ArguablySane
Member
 
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: understanding get_look_dir()

by ArguablySane » Sat Dec 13, 2014 15:54

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.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

User avatar
LocaL_ALchemisT
Member
 
Posts: 56
Joined: Thu Jul 19, 2012 16:21
Location: Asia Tenggara
 

User avatar
Hybrid Dog
Member
 
Posts: 2731
Joined: Thu Nov 01, 2012 12:46

Re: understanding get_look_dir()

by Hybrid Dog » Tue Dec 16, 2014 18:51

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.

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪
 

User avatar
ArguablySane
Member
 
Posts: 116
Joined: Sun Oct 12, 2014 21:29

Re: understanding get_look_dir()

by ArguablySane » Tue Dec 16, 2014 23:02

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.
The above post and any ideas expressed therein are released to the public domain under a Creative Commons CC0 license.
 

User avatar
Hybrid Dog
Member
 
Posts: 2731
Joined: Thu Nov 01, 2012 12:46

Re: understanding get_look_dir()

by Hybrid Dog » Wed Dec 17, 2014 14:00

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

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 3 guests