View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:22 pm



Reply to topic  [ 12 posts ] 
 Circular Motion 
Author Message
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Circular Motion
It's a pretty basic topic if you know what you're doing. Unfortunately, I do not. This is what I've come to so far:
Code:
function Create(self)
  circlex = self.Pos.X;
  circley = self.Pos.Y;
  radius = 10;
  speed = (2 * math.pi * radius)/2
  speedScale  = speedScale + .5;
 end

function Update(self)
  angle = speedScale;
  self.Pos.X = circlex + math.sin(angle)*radius;
  self.Pos.Y = circley + math.cos(angle)*radius;
end


I'm pretty positive it has to do with speed/speedscale, but I'm unable to find what it is.
Any help would be greatly appreciated.

Edit: It's the fact that I don't get how to constantly make the point actually MOVE around the circle, rather than it being a static point on the circle.


Thu Feb 24, 2011 1:20 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Circular Motion
The problem is that the variable "angle" never changes. You're just setting it to the same value every frame, instead of incrementing it.


Thu Feb 24, 2011 1:57 am
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Circular Motion
But that's what I don't get. I have angle(SpeedScale) increasing in increments of 0.5... Idk why I have two variables when I could have just one, but it should steadily increase by .5 every single frame, no? I'm sure it's something dumb that I'm not noticing, but like I said I can't get it.
And should it decrease back to 0 once it does reach 180, right? (By adding code, of course)
Code:
function Create(self)
  circlex = self.Pos.X;
  circley = self.Pos.Y;
  radius = 10;
  speed = (2 * math.pi * radius)/2
  speedScale  = speedScale + .5;
end

function Update(self)
  angle = speedScale;
  self.Pos.X = circlex + math.sin(angle)*radius;
  self.Pos.Y = circley + math.cos(angle)*radius;
end


Thu Feb 24, 2011 2:04 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Circular Motion
It will only update if it's in the update function. Declare speedscale in create, then increment it in update.


Thu Feb 24, 2011 2:08 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Circular Motion
I love you, TLB and Roast Veg both. I seriously appreciate the help, guys. Thanks a lot.
(it worked)


Thu Feb 24, 2011 2:14 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Circular Motion
Code:
function Create(self)
  circlex = self.Pos.X;
  circley = self.Pos.Y;
  radius = 100;
  radiuscheck = true;
  speedScale  = 0;
 
 end

function Update(self)
if radius == 100 then
radiuscheck = false;
end

if radius > 99 and radiuscheck == false then
radius = radius + 1;
elseif radius > 200 then
radius = radius - 1;
elseif radius < 50 then
radius = radius + 1
end


speedScale = speedScale + 0.1;
if speedScale > 180 then
speedScale = 0;
end

  angle = speedScale;
  self.Pos.X = circlex + math.cos(angle)*radius;
  self.Pos.Y = circley + math.sin(angle)*radius;
end


Alright I'm trying to make the radius increase to 200 then decrease back to 100 continuously, but I can't figure out how to through checks. It just keeps increasing, for I can see the radius = radius + 1 is overriding the "if radius > 200" statement. I just don't know how to fix it.
Thanks again!


Thu Feb 24, 2011 2:39 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Circular Motion
Code:
function Create(self)
    circlex = self.Pos.X;
    circley = self.Pos.Y;
    radius = 100;
    radiuscheck = true;
    speedScale  = 0;
    reverse = false;
end

function Update(self)
    if radius == 50 then
        reverse = false;
    elseif radius == 200 then
        reverse = true;
    end

    if reverse == false then
        radius = radius + 1;
    else
        radius = radius -1;
    end

    speedScale = speedScale + 0.1;
    if speedScale > 180 then
        speedScale = 0;
    end

    angle = speedScale;
    self.Pos.X = circlex + math.cos(angle)*radius;
    self.Pos.Y = circley + math.sin(angle)*radius;
end


Thu Feb 24, 2011 2:50 am
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Circular Motion
That makes so much more sense. Changing the values at specific values rather than a range of them.
Thanks <3


Thu Feb 24, 2011 3:02 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Circular Motion
Don't mention it. I'm having rather the Lua filled evening anyway.


Thu Feb 24, 2011 3:03 am
Profile
User avatar

Joined: Tue Mar 16, 2010 7:38 pm
Posts: 447
Location: The Ninth Circle
Reply with quote
Post Re: Circular Motion
Just to add to your Lua-filled evening, how well does Lua handle parametric equations? I'm wondering if that might help with defining this sort of thing.


Thu Mar 03, 2011 1:25 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Circular Motion
I'm not sure what you mean by that. You don't really use equations in programming.


Thu Mar 03, 2011 1:33 am
Profile WWW
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Circular Motion
Lua would handle parametric equations just fine, but it's probably easier and more efficient to chuck it all on the one line.


Thu Mar 03, 2011 7:58 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

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.155s | 13 Queries | GZIP : Off ]