Trig problem, can't figure out left and right.
#1

Ok so if I use this code:

pawn Код:
x += ( distance * floatsin( -angle, degrees ) );
y += ( distance * floatcos( -angle, degrees ) );
It will give me the point infront or behind the x/y based on the distance variable (pos/neg value passed).

How do I do left or right though ?
Reply
#2

I haven't looked into this much, but try swapping the X/Y formulae and seeing what the result is. Might be left/right.

EDIT: after some head scratching and mid-air hand gestures I think swapping them will work. To put something to the right you need a positive distance, and to the left a negative one. Things would be:

pawn Код:
x += ( distance * floatcos( -angle, degrees ) );
y += ( distance * floatsin( -angle, degrees ) );
Reply
#3

Edit: ignore this I'll read your edit and test it.
Reply
#4

So you want to get a point next to it or like north east of it?
Reply
#5

@Wierdosport

Didn't test that code dude but it will just give an opposite effect as the sum is still the same but on the other axis.

@Backwardsman

I'm after a formula so that I can get the point to the left or right from a given point, not a compass point but a point based on my angle. The one above does it for forwards and backwards based on your angle but I'm having trouble working out left and right.

Edit:

Actually I will go and test it as I don't want to be an idiot and skip past it.

Edit 2:

Yep it does the same, no joy.
Reply
#6

It wont give an opposite effect, that is done by changing -angle to angle. By changing which axis you alter, I am reasonably confident it would give the desired effect. I've tested it on 90 degree angles and it gave the results I'd expect.
Reply
#7

Edit:

This is the working one:

pawn Код:
x += ( distance * floatcos( angle, degrees ) );
y += ( distance * floatsin( angle, degrees ) );
I removed the '-' from the angle, it works like a treat from what I've just tested (hope I've not spoken to soon lol).

I got confused before when you said the opposite is the correct one, I thought you meant the distance so as you can imagine that didn't work and just went the other way hehe.

Thanks for the help dude, I appreciate it !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)