View unanswered posts | View active topics It is currently Fri Mar 29, 2024 7:09 am



Reply to topic  [ 1 post ] 
 Circles 
Author Message
User avatar

Joined: Sun May 11, 2008 12:50 pm
Posts: 899
Reply with quote
Post 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).


Sat Jul 25, 2009 12:18 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.058s | 15 Queries | GZIP : Off ]