LoginLogin

How to make a line that faces something

Root / Programming Questions / [.]

VakoreCreated:
I'm trying to make a line face a point. However, I'm not sure how to mathematically do this. I tried googling, but no luck(it seems to think that I want to know how to draw a line, or do it in unity). I'm not talking about having a line drawn from one point to another, I mean have it FACE the point, and I don't want to use a rotate function either, because I need this for testing collision with something. For instance, a line with a length of 100 pixels, always, and when the player(the second point) is 50px below the first point, and is on the same X position as it, the line will be drawn down, with 50px of line leftover below the player. I've tried using the sin and cos of the slope of the line, but that just spazes out. Thanks in advance!

You'll have to draw a picture, I'm having a hard time figuring out what you mean.

I dunno... but:
SX=200
SY=120
PX=RND(400)
PY=RND(240)
ANG=ATAN(PY-SY,PX-SX) 'get angle between player and centre
EX=SX+COS(ANG)*50 'trig stuff
EY=SY+SIN(ANG)*50  'trig stuff: the rehappening
GLINE SX,SY,EX,EY

I'll draw pics later, and I'll test bananas solution later.

You mean a bit like a shield? Yeah, Banana's mostly right. You'll want to add 90 degrees to the angle (so that it changes from the direction between the two points, to its "normal") Then you draw.. X1=SX+Cos(Ang)*50 : X2=SX+Cos(Ang+180)*50 Y2=SY+Sin(Ang)*50 : Y2=SY+Sin(Ang+180)*50

Yeah, like a shield. Thanks guys!

I made a highly commented example (everytime I comment a line of code I die) of this, in case you need it. Key: 5KE33PCX

Angles vs me. Not a good combination. Somewhere between the ATan2, the occasional Rad/Deg converting, the confusion of some certain languages flipping the Y co-ords around, and my own second-guessing,, I can NEVER get my angles right on the first try. Always have to code/test/fix.. every single time!!

Angles vs me. Not a good combination. Somewhere between the ATan2, the occasional Rad/Deg converting, the confusion of some certain languages flipping the Y co-ords around, and my own second-guessing,, I can NEVER get my angles right on the first try. Always have to code/test/fix.. every single time!!
Trigonometry: Attack on Titan Angles

I tried it out, and it worked(with a little tweaking)! Thanks guys!

\o/yeay\o/