Getting the exact spot the player is pointing at

Post Reply
User avatar
12Me21
Member
Posts: 873
Joined: Tue Mar 05, 2013 00:36
GitHub: 12Me21
Location: (Ignore all of my posts before 2018)

Getting the exact spot the player is pointing at

by 12Me21 » Post

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.

Byakuren
Member
Posts: 818
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri
In-game: Raymoo + Clownpiece

Re: Getting the exact spot the player is pointing at

by Byakuren » Post

What about Raycast? (which is coming in the 5.0.0 modding API)
Every time a mod API is left undocumented, a koala dies.

User avatar
12Me21
Member
Posts: 873
Joined: Tue Mar 05, 2013 00:36
GitHub: 12Me21
Location: (Ignore all of my posts before 2018)

Re: Getting the exact spot the player is pointing at

by 12Me21 » Post

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

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: Getting the exact spot the player is pointing at

by Wuzzy » Post

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

User avatar
12Me21
Member
Posts: 873
Joined: Tue Mar 05, 2013 00:36
GitHub: 12Me21
Location: (Ignore all of my posts before 2018)

Re: Getting the exact spot the player is pointing at

by 12Me21 » Post

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.

User avatar
Hybrid Dog
Member
Posts: 2828
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Getting the exact spot the player is pointing at

by Hybrid Dog » Post

You'd just need to test the position on all selection boxes and select the one nearest to the player.

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

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests