Legacy GM lengthdir_x,y help

V

VeSo

Guest
Heyall, I'm trying to skip the trigonometry because it's just not working for me regarding all the different negative numbers i'm working with.

1588231408118.png
I want to jump from x,y1 at an angle (direction) of 280 degrees and 100 pixels in said direction in order to land on x,y2.
I cannot for the life of me figure this out. You would imagine it requires some kind of code that does this:

position_direction_add code (position x,position, y, direction, amount)

Obviously no such function exists so I'm stuck with lengthdir.

The problem is lengthdir_x and lengthdir_y are asking me for values I won't know. (A squared + B squared = C sqrd)

So in short, I just want to add a certain length in a direction.

Thanks!
 

Attachments

NightFrost

Member
I'm little confused. Initially you say you know the length of the hypotenuse (100 pixels) which is what lengthdirs want, but then you say you don't. A triangle cannot be solved if all three sides are unknown.
 

sylvain_l

Member
whats more confusing in your picture is that you have a 280° angle, but you label both point x, y1 and x, y2 (why/how the hell both have same x ?)

something doesn't add up here.
 
V

VeSo

Guest
Clearly didn’t read the question. I’n trying to avoid trigonometry because the angles i’m working with are negative.

I simply want to jump the required distance 100px, in the required direction, 280deg
 

Nidoking

Member
What, precisely, is the quantity that lengthdir is asking for that you don't have? The use of the Pythagorean Theorem is internal. You need a direction and a distance, and you listed both, so what's the thing you're not putting in your question?
 
V

VeSo

Guest
This really is self explanatory and very simple. I want to move 100 pixels in the direction of 280 degrees and need to know how or what function I use to get there.
 

GMWolf

aka fel666
This really is self explanatory and very simple. I want to move 100 pixels in the direction of 280 degrees and need to know how or what function I use to get there.
Nothing wrong with lengthdir in that case. You have your direction and your length.
Trig doesn't care about negative angles, or even angles greater than 360. It works.
 

FrostyCat

Redemption Seeker
If your idea of trigonometry doesn't work with angles outside the 0-90 range, it's that wrong idea you should be avoiding.

This works just fine:
GML:
x += lengthdir_x(100, 280);
y += lengthdir_y(100, 280);
And the function you thought was impossible:
GML:
///@func position_direction_add(x, y, direction, amount)
///@param x
///@param y
///@param direction
///@param amount
return [argument0+lengthdir_x(argument3, argument2), argument1+lengthdir_y(argument3, argument2)];
 
Top