Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Time Control

Is there anyway for me to somehow manipulate how fast time goes in my project or like slow physics down to make it look like that time is slowing down?

Thanks in advance :)

Comments

  • Posts: 2,364

    @Creator27 - the only way I know to slow things down is to build into your display routine a variable delay which you control from the system timer or just increment the delay loop variable. It could get a little jerky though especially if you have something like a logarithmic decay.

    Not sure if this works with physics though as that should drive to its own timetable.

  • Posts: 104

    @Bri_G, I’m not so sure what you mean. Could you possibly show me an example of what you mean?

    Thanks :)

  • edited September 12 Posts: 172

    i added a simple way to do this into my project -

    set a parameter or global var called TIME_SCALE

    and add a wrapping class for physics. body and one for your game object (craft model) and give them an update function that you call in your draw

    then in the update you detect the diff in position and multiply it by TIME_SCALE and set the position to the new one -

    function Body:init()
      self.prevX = 100
      self.prevY = 100
      self.body = physics.body()
      self.body.x = self.prevX 
      self.body.y = self.prevY
      self.prevAngle = 0
      self.body.angle = self.prevAngle
    end
    
    function Body:update()
       if self.body.x ~= self.prevX then
        local diff = (self.prevX - self.body.x) * TIME_SCALE 
        self.prevX = self.prevX - diff
        self.body.x = self.prevX
        if self.GameObject then
          self.GameObject.x = self.body.x
        end
      end
    
      if self.body.y ~= self.prevY then
        local diff = (self.prevY - self.body.y) * TIME_SCALE 
        self.prevY = self.prevY - diff
        self.body.y = self.prevY
        if self.GameObject then
          self.GameObject.y = self.body.y
        end
      end
    
      if self.body.angle ~= self.prevAngle then
        local diff = (self.prevAngle - self.body.angle) * TIME_SCALE 
        self.prevAngle = self.prevAngle - diff
        self.body.angle = self.prevAngle
        if self.GameObject then
          self.GameObject.angle = self.body.angle
        end
      end
    
    end
    
    

    and basically the same thing for anywhere you want to see timescale have an effect you would do a similar thing

Sign In or Register to comment.