Screen click to world pos.
by Dan - · in Torque Game Engine · 05/29/2005 (9:13 pm) · 1 replies
I was wondering if anyone had any advice on getting the world location that the users mouse is over?
My goal is to create a game grid or game board. Easiest way to think of it would be that the entire checkers board is one object and the user is looking at it. When the user places his mouse "over" a square in the object it would change color. I don't want to rely on the board being 50% of the screen or that the user is looking straight down at it.
I have worked on this a bit. I can get the cursor (or mouse) location by using the global Canvas object. The worldEditor uses a function called screenToWorld which I have converted to be used in my object but it always returns really bogus numbers. So I know I did something wrong.
There are also some resources that deal with selection of an object, but I really need part of the object being selected.
So in summary I am looking for finding out the world x/y (and Z) location that the user is clicking on via the Canvas object.
Make sense?
Thank you for your time,
My goal is to create a game grid or game board. Easiest way to think of it would be that the entire checkers board is one object and the user is looking at it. When the user places his mouse "over" a square in the object it would change color. I don't want to rely on the board being 50% of the screen or that the user is looking straight down at it.
I have worked on this a bit. I can get the cursor (or mouse) location by using the global Canvas object. The worldEditor uses a function called screenToWorld which I have converted to be used in my object but it always returns really bogus numbers. So I know I did something wrong.
There are also some resources that deal with selection of an object, but I really need part of the object being selected.
So in summary I am looking for finding out the world x/y (and Z) location that the user is clicking on via the Canvas object.
Make sense?
Thank you for your time,
Torque Owner Neil Marshall
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7335
You need to project a ray out from the position they clicked on the screen and see which objects it intersects with.