Data Realms Fan Forums http://45.55.195.193/ |
|
Circles http://45.55.195.193/viewtopic.php?f=73&t=15991 |
Page 1 of 1 |
Author: | Roon3 [ Sat Jul 25, 2009 12:18 pm ] |
Post subject: | Circles |
Most mods that use object moving in a circular motion use some hacky emitters, timers or other inaccurate methods. If you want to have easy circles in your mod, read on. This is the function I use: Code: function circle(Radius,Angle,ObjectStartX,ObjectStartY) return Vector((math.cos(Angle)*Radius)+ObjectStartX,(math.sin(Angle)*-Radius+ObjectStartY)); end Now some of you are probably thinking: "OH NOES TRIG I DUNT NO TRIG HALP PLIZ!!!1!1!!" Well here's how it works: In trig, doing cos(θ),sin(θ) will give the coordinates of a vector in the direction θ is facing with a magnitude of 1. multiplying both coordinates by N will give us the coordinates with magnitude of N (N being the radius of our circle). So Code: Vector((math.cos(Angle)*Radius),(math.sin(Angle)*-Radius)) Works the same way as Vector( cos(θ)*N, sin(θ)*-N). If we add this to our object's start position it will move to the point specified by the vector. Code: return Vector((math.cos(Angle)*Radius)+ObjectStartX,(math.sin(Angle)*-Radius+ObjectStartY)); This is not all, we also need to change the direction our angle is pointing at, causing the object to move in a circle. So, in the update part of code your code add: Code: MyAngle = MyAngle + M This is the end result. I hope you learned something here, enjoy! tl;dr: Just run this script on any object to make it move in a circle. PS. I've never learned trig (nor have I had the option to) so if there's anything wrong or inaccurate, I apologize (And if you point it out, I will fix it). |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |