Data Realms Fan Forums
http://45.55.195.193/

Circular Motion
http://45.55.195.193/viewtopic.php?f=73&t=21567
Page 1 of 1

Author:  Mind [ Thu Feb 24, 2011 1:20 am ]
Post subject:  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.

Author:  TheLastBanana [ Thu Feb 24, 2011 1:57 am ]
Post subject:  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.

Author:  Mind [ Thu Feb 24, 2011 2:04 am ]
Post subject:  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

Author:  Roast Veg [ Thu Feb 24, 2011 2:08 am ]
Post subject:  Re: Circular Motion

It will only update if it's in the update function. Declare speedscale in create, then increment it in update.

Author:  Mind [ Thu Feb 24, 2011 2:14 am ]
Post subject:  Re: Circular Motion

I love you, TLB and Roast Veg both. I seriously appreciate the help, guys. Thanks a lot.
(it worked)

Author:  Mind [ Thu Feb 24, 2011 2:39 am ]
Post subject:  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!

Author:  Roast Veg [ Thu Feb 24, 2011 2:50 am ]
Post subject:  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

Author:  Mind [ Thu Feb 24, 2011 3:02 am ]
Post subject:  Re: Circular Motion

That makes so much more sense. Changing the values at specific values rather than a range of them.
Thanks <3

Author:  Roast Veg [ Thu Feb 24, 2011 3:03 am ]
Post subject:  Re: Circular Motion

Don't mention it. I'm having rather the Lua filled evening anyway.

Author:  Nocifer [ Thu Mar 03, 2011 1:25 am ]
Post subject:  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.

Author:  TheLastBanana [ Thu Mar 03, 2011 1:33 am ]
Post subject:  Re: Circular Motion

I'm not sure what you mean by that. You don't really use equations in programming.

Author:  411570N3 [ Thu Mar 03, 2011 7:58 am ]
Post subject:  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.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/