How to calculate mouse world position?

Hi, I am new to Defold, but I really need it to make a game, so this question can be very noob (I don’t know, I am new to this engine), but I not find nothing in this forum, so I decided to create an topic.
Basically, I need to get the mouse world position when the player clicks on some place of the screen, this is very simple to do with other programming languages, like Java (being almost expert in Java is so cool, but is very expensive, and I choose Defold) but Defold uses Lua, and I don’t know nothing about Lua, and nothing of I do can give me this simple information. I need to know the position based on player location (camera location, I don’t know, but my camera is not on player center, is on bottom left), because the player moves around the world.
Please help, I need very very very much.

1 Like

I recommend you go through these examples and study / look through them in general as you are new.

The specific information you need to look into is getting the mouse x,y from the

function on_input(self, action_id, action)
	if action.released then
		-- do something with action.screen_x and action.screen_y 
	end
end

And then offset based on your camera.

Tackle one issue at at time it will make it easier.

If you post some of your code people can help with guiding you in the right direction more.

1 Like

You can also check out our recently launched examples section, @Taarak—it contains a handful of useful code samples. And welcome to Defold!

This link returns 404 to me, do these examples no longer exist?

Self promotion incoming: My Orthographic Camera lib has a screen_to_world and vice versa. If you don’t want the whole lot I’m sure you’re able to just grab those few lines of code.

2 Likes

https://www.defold.com/examples/ is the correct link :slight_smile:

2 Likes

Thank @Axel !

1 Like

This is exactly what I’m looking for :smiley: thanks

1 Like