How can I get the opposite of a direction?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

How can I get the opposite of a direction?

Post by pyxledev »

Like adding 180 degrees to and angle. I don't think there is any more explanation needed for this.
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: How can I get the opposite of a direction?

Post by darkfrei »

pyxledev wrote: Sun Sep 11, 2022 11:32 am Like adding 180 degrees to and angle. I don't think there is any more explanation needed for this.
Pi is 180 degrees for any angle calculations:

Code: Select all

opposite = direction + math.pi
Also 90 degrees is half pi and 360 degrees is a 2*pi. But people must to know about the Tau.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: How can I get the opposite of a direction?

Post by pgimeno »

How is the direction given? If it's a vector, then just change the signs of the components.
User avatar
pyxledev
Prole
Posts: 23
Joined: Tue Jul 26, 2022 2:19 pm
Contact:

Re: How can I get the opposite of a direction?

Post by pyxledev »

darkfrei wrote: Sun Sep 11, 2022 12:13 pm
pyxledev wrote: Sun Sep 11, 2022 11:32 am Like adding 180 degrees to and angle. I don't think there is any more explanation needed for this.
Pi is 180 degrees for any angle calculations:

Code: Select all

opposite = direction + math.pi
Also 90 degrees is half pi and 360 degrees is a 2*pi. But people must to know about the Tau.
Thanks so much. That worked.
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: How can I get the opposite of a direction?

Post by milon »

darkfrei wrote: Sun Sep 11, 2022 12:13 pm ... But people must to know about the Tau.
Off topic, but thanks for sharing that link! I'm a bit of a math nerd and I hadn't heard about that. :D
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: How can I get the opposite of a direction?

Post by ReFreezed »

All hail Tau - the more sensible constant!
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests