Page 1 of 1

Getting the exact spot the player is pointing at

PostPosted: Sun Sep 02, 2018 20:58
by 12Me21
Right now there's no easy way to find out what part of a node the player is looking at, using the Lua API.
(That is, the exact position where the camera vector first intersects with a node/entity selection box)

It's relatively simple to figure out when you're dealing with full nodes, but complex nodeboxes make it a lot harder. I have a (mostly) working solution, but it's very complicated and there are a few situations where it won't work. (I have no way of compensating for the view bobbing animation, for example) (Plus, if any new node box types are added to the game (like the "disconnected" nodeboxes being added in version 0.5), I'll have to update my code.)

If there was a built in function which tells you exactly where the player is looking, that would be very helpful.
pos, face = player:get_pointed_pos() (or something)
(The ability to tell which face of the node you are pointing at is also very important)

There are a ton of situations where this would be useful.

Re: Getting the exact spot the player is pointing at

PostPosted: Wed Sep 05, 2018 22:28
by Byakuren
What about Raycast? (which is coming in the 5.0.0 modding API)

Re: Getting the exact spot the player is pointing at

PostPosted: Thu Sep 06, 2018 01:20
by 12Me21
Byakuren wrote:What about Raycast? (which is coming in the 5.0.0 modding API)

Yeah, that does exactly what I needed
I was going to update my post but I forgot...

Re: Getting the exact spot the player is pointing at

PostPosted: Wed Sep 19, 2018 07:22
by Wuzzy
No need to wait:
Code: Select all
 * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
     * returns the exact position on the surface of a pointed node

Re: Getting the exact spot the player is pointing at

PostPosted: Mon Sep 24, 2018 20:16
by 12Me21
Wuzzy wrote:No need to wait:
Code: Select all
 * `minetest.pointed_thing_to_face_pos(placer, pointed_thing)`: returns a position
     * returns the exact position on the surface of a pointed node

That doesn't work with nodes that use nodeboxes.

Re: Getting the exact spot the player is pointing at

PostPosted: Thu Oct 04, 2018 10:26
by Hybrid Dog
You'd just need to test the position on all selection boxes and select the one nearest to the player.