Measuring distance between object and touch on screen

jrj.clarkjrj.clark Member, PRO Posts: 17

Hi there, I'm using Pythagorean Theorem to calculate the distance between where a player touches the screen and an object on the screen. ie. a2 + b2 = c2. This works fine on a scene that is the same size as the screen.

However, on a scene larger than the screen size things go wrong. Let's use the x co-ordinate to illustrate the problem. I'm using self.position.x to get the location of the object - this keeps increasing as it moves across the scene. And I'm using game.mouse.position.x to get the location of where the touch is on the screen - this remains the same even if the scene is moving. Therefore, as the object moves right, the distance between these two points grows.

I think I need to change one of these two to mirror the other. But I'm not sure how. Any suggestions?

Thanks in advance,
James

Comments

Sign In or Register to comment.