smark1
smark1

Reputation: 21

Game maker lengthdir inner implementation

I wonder how lenghtdir_x/y is implemented. To my understanding this has something to do with trigonometry but since I'm a fairly new to all of this I can't figure it out myself.

Upvotes: 2

Views: 396

Answers (1)

YellowAfterlife
YellowAfterlife

Reputation: 3202

You are correct, it is a bit of trigonometry - namely, converting from degrees to radians, and then multiplying a sine/cosine of that angle by "length" (hence why it is called length-dir)

lengthdir_x(l, d) is l * cos(d * pi / -180)

lengthdir_y(l, d) is l * sin(d * pi / -180)

live demo for comparison

enter image description here

Upvotes: 2

Related Questions