X and Y co-ordinates are wrongly displayed?.. (Pic)

V

VeSo

Guest
upload_2019-2-12_12-11-52.png
The ball in my game is running a code that returns the value for the distance between itself and the arrow. However this is completely WRONG.

The ball is a 64px sprite and is probably less than 100px away from the arrow, yet the reading (top left) is saying its 641.63?

Have I missed something? I checked over all of my objects for any accidental relatives or multi's. NOTHING. Very weird. Any help would be wicked! thanks!
 

YoSniper

Member
Can you post the code you are using?

I get the feeling that you are writing the raw X of the object, and not the difference in X.
 
V

VeSo

Guest
For the object ball
STEP EVENT


globalvar DIST;
DIST = distance_to_point(o_target.x,o_target.y)

x = mouse_x
y = mouse_y
 
Are you drawing the arrow on a gui layer? Or using a view?
Try to find the point in the room where it says the distance is 0. Does the distance get smaller when you bring the ball closer to the target?
 
V

VeSo

Guest
I've done exactly that. It appears the distance wont go below a certain number and 0 isn't locatable with the mouse. very odd
 

YoSniper

Member
Quick thought: that o_target object. Does it actually exist in the room? Maybe you misspelled the object name?

There is an option in Game Maker where if an object instance or variable is unknown, it defaults to zero.
 
That is weird..

Add this to the draw event of the ball and arrow objects and see if they are similar when you put the ball near the target:
Code:
draw_self();
draw_text(x,y+32,"("+string(x)+","+string(y)+")");
 
V

VeSo

Guest
Fixed it. Don't ask how- I don't know. I started a new project, ran the same objects and code but in a smaller 640*480 room and everything checks out which is odd. I feel you were right and that something went wrong with views and scaling.
 

Attachments

johnwo

Member
First off, the use of globalvar is only included for backwards compatibility, so use of it is not recommended. (Source)

Using something like the code below should yield the desired result:
Code:
// Create event:
global.dist = -1;

// Step event
global.dist = point_distance(mouse_x,mouse_y,o_target.x,o_target.y);

// Draw event
draw_text(32,32,"Distance between o_target and mouse-pointer = "+string(global.dist));
Use this to figure out where you went wrong.

If you're scaling views(zooming) etc. the distance will still be the same no matter the amount of scaling used. If you want the distance between two points relative to the amount of scaling, you'll have to manually calculate it (dist*scaleFactor etc.).
 
Top