generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Rotating an object based on vector direction

Previous Thread :: Next Thread 
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
11 Apr 2012 11:10 AM
Say I have a thin projectile image facing upwards, and the direction it needs to go in it (0,1). I would want to rotate it 90 degrees. Is there an algorithm to work this out, so that it can be reusable rather than writing different sections for each object?
Report Abuse
miloguy is not online. miloguy
Joined: 19 Dec 2009
Total Posts: 7702
11 Apr 2012 12:29 PM
Is this 2D?
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
11 Apr 2012 12:31 PM
What do you think if the direction is 0,1 :P?
I might have some formula let me search for it :PP
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
11 Apr 2012 12:33 PM
Do you mean this?

Angle = Math.Atan2(DirectionX, -rocketDirectionY);
Report Abuse
miloguy is not online. miloguy
Joined: 19 Dec 2009
Total Posts: 7702
11 Apr 2012 12:35 PM
or just

angle = math.atan2(direction.y,direction.x)
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
11 Apr 2012 12:35 PM
Angle = Math.Atan2(DirectionX, -DirectionY)*

Uhh... I forgot to take the rocket out before direction.. That's straight from one tutorial :PP
Report Abuse
miloguy is not online. miloguy
Joined: 19 Dec 2009
Total Posts: 7702
11 Apr 2012 12:37 PM
its better to keep a record of the direction as an angle then get the vector direction when you need it if you're doing something like a rocket.
y before x in atan2 usually, that tutorial is weird (x, -y probably works though)
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
11 Apr 2012 12:41 PM
Well shouldn't it be in le alphabetic order?
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
11 Apr 2012 12:43 PM
Yes, it's 2D. atan2, seen it before but I don't know what it does... googling
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
11 Apr 2012 12:54 PM
Arc tangent^
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
11 Apr 2012 12:56 PM
Don't know what an arc tangent is either ^^
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
11 Apr 2012 01:01 PM
"For any real number (e.g., floating point) arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it"

i should get to know these functions a bit more
Report Abuse
trappingnoobs is not online. trappingnoobs
Joined: 05 Oct 2008
Total Posts: 19100
11 Apr 2012 02:12 PM
you say it like I don't know what arc tangent is

of course I know what arc tangent is! you dare insult my knowledge of arc tangent?


it's.. uh.. the.. uh.. arc of a tangent?
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
11 Apr 2012 02:22 PM
[ Content Deleted ]
Report Abuse
miloguy is not online. miloguy
Joined: 19 Dec 2009
Total Posts: 7702
11 Apr 2012 06:53 PM
the only trig (maybe a little more for rare cases) you need to know for 2D game developement is

vector(cos(angle),sin(angle)) = angle to unit vector

atan2(vector.y,vector.x) = unit vector to angle

sqrt(squared(a.x-b.x)+squared(a.y-b.y)) = distance between points a and b

(degrees/180)*pi = degrees to radians
(radians/pi)*180 = radians to degrees
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
11 Apr 2012 07:07 PM
The irritating thing is I like to be able to manipulate this stuff - I know almost all of the maths for this kind of thing except for trig functions like cos and sin, because I have absolutely no idea what they are :(
Report Abuse
ZackZak is not online. ZackZak
Joined: 26 Jul 2009
Total Posts: 2811
11 Apr 2012 07:19 PM
Use atan2(y, x) to convert to an angle, then offset the angle and covert it back into a vector with (math.cos(x), math.sin(y)).
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image