Howdy, Stranger!

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

Animating an object in a parabolic motion

edited June 2014 in General Posts: 142

Hi,
I'm new to programming on Codea and apps in general. What is the best way to animate an object (such as an ellipse) in an arc like a parabola (in a parabolic motion)? I've searched around on the forums and online and I can't seem to figure it out.
Thanks!

Comments

  • dave1707dave1707 Mod
    Posts: 7,533

    @Staples I'm not sure what you're after, but is it something like this.


    displayMode(FULLSCREEN) supportedOrientations(LANDSCAPE_ANY) function setup() b=physics.body(CIRCLE,5) b.x=50 b.y=50 b.gravityScale=0 show=true end function draw() background(40, 40, 50) fill(255) if show then text("tap screen",WIDTH/2,HEIGHT-100) end ellipse(b.x,b.y,10) if b.y<0 then restart() end end function touched(t) if t.state==BEGAN then b.gravityScale=1 b.linearVelocity=vec2(300,500) show=false end end
  • Posts: 142

    Yeah that's perfect. I tried using a variable "thrust" like in the Lunar Lander tutorial, but it didn't look as professional as this. Thanks!

  • Posts: 142

    @dave1707 How would you get this to animate upon loading? I've tried putting the code from function touched(t) in the draw() function and nothing happened. I've also tried having a separate function called animate() where a timer is set in the draw() function and the animate() function is called every 300 frames, but neither of those seem to work.

  • dave1707dave1707 Mod
    Posts: 7,533

    @Staples This animates upon loading.


    displayMode(FULLSCREEN) supportedOrientations(LANDSCAPE_ANY) function setup() b=physics.body(CIRCLE,5) b.x=50 b.y=50 b.gravityScale=1 b.interpolate=true b.linearVelocity=vec2(300,500) show=false end function draw() background(40, 40, 50) fill(255) if show then text("tap screen",WIDTH/2,HEIGHT-100) else ellipse(b.x,b.y,10) if b.y<0 then b:destroy() show=true end end end function touched(t) if t.state==BEGAN then restart() end end
  • edited September 2014 Posts: 142

    @dave1707 Thanks!

Sign In or Register to comment.