Jump to content


Problem With Drawing Line Based On Direction

  • This topic is locked This topic is locked
2 replies to this topic

#1 Nijg


    Caleb Cuzner

  • GMC Member
  • 1166 posts
  • Version:GM6

Posted 14 August 2009 - 04:30 PM

I am trying to draw a line that takes the direction from one point to another, and then draws a line in that direction, with the line being 800 pixels long. Here is the basic code of what I have tried:
This is trying to draw the line from Protagonist's origin in the direction of Prot_aimer's orgin, extending for 800 pixels. Prot_aimer is a moving object so its origin varies, but its direction from Protagonist is always between 0 degrees and 180 degrees.

Whenever I use this code, the line is 800 pixels long as planned, but it is always going in the wrong direction, usually favoring towards the bottom left. I have tried switching the Protagonist coordinates and Prot_aimer coordinates with each other in point_direction. I have tried adding 90, adding 180, or subtracting 180 from the direction. I have tried switching the directions to negatives. I have tried using if statements declaring if the direction is supposed to be generally towards the left or generally towards the right. I have tried making the length shorter. None of these fixed the direction problem, and they usually ended up in the direction being towards the bottom left.

I have searched if there is code to do this on GMLscripts.com, and could not find any. Please help if you can.

Edited by Nijg, 14 August 2009 - 06:06 PM.

  • 0

#2 turgon


    VP Studios

  • GMC Member
  • 550 posts
  • Version:GM:Studio

Posted 14 August 2009 - 04:37 PM

Perhaps I'm misunderstanding your question, but from what I understand, you're looking for something like this:



Good luck; I hope this helps!

Edited by turgon, 14 August 2009 - 04:39 PM.

  • 0

#3 Nijg


    Caleb Cuzner

  • GMC Member
  • 1166 posts
  • Version:GM6

Posted 14 August 2009 - 05:55 PM

Wow, I can't believe I overlooked that lengthdir stuff in the help file.

All this time I have been trying to use trigonometry to figure out that type of stuff, and all along there was a built-in function that could do it for me...

Well it works now, thanks for pointing that out.

Edited by Nijg, 14 August 2009 - 05:55 PM.

  • 0