Howdy, Stranger!

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

Trajectory of flight

I haven't found any lessons, were you can be learned for it. Can you give me tags of how to search for it? For example I tried trajectory, flight, path, but they didn't gave me a link. I am confused, so I tried to ask you, if the physic engine Codea gives would be possible to use?

Comments

  • dave1707dave1707 Mod
    Posts: 7,602

    Do you want the trajectory of something like a bullet or the trajectory of a space ship in orbit. The physics engine would do a bullet type trajectory with very little code.

  • dave1707dave1707 Mod
    edited February 2017 Posts: 7,602

    Since I don't know what you want, here's an example of an Angry Bird type of trajectory.

    supportedOrientations(LANDSCAPE_ANY)
    displayMode(FULLSCREEN)
    
    function setup()
        b=physics.body(CIRCLE,10)
        b.x=10
        b.y=10
        b.type=STATIC
        physics.continuous=true
    end
    
    function draw()
        background(0)
        fill(255)
        ellipse(b.x,b.y,20)
        text("tap screen to shoot",WIDTH/2,HEIGHT-50)
        if b.y<0 then
            b.type=STATIC
            b.x=10
            b.y=10
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            b.type=DYNAMIC
            b.linearVelocity=vec2(300,500)
        end
    end
    
  • dave1707dave1707 Mod
    Posts: 7,602

    If you don't want to use physics, try this. Change dt, grav, xSpeed, or ySpeed for the effect you want.

    displayMode(FULLSCREEN)
    
    function setup()
        x,y,t=0,0,0
        dt=1/60 -- time interval
        grav=16 -- gravity
        xSpeed=130  -- x initial velocity
        ySpeed=130  -- y initial velocity
    end
    
    function draw()
        background(0)
        fill(255)
        t=t+dt
        x=t*xSpeed
        y=t*ySpeed-(t*t*grav)
        ellipse(x,y,10)
        text("tap screen to shoot",WIDTH/2,HEIGHT-50)
    end
    
    function touched(t)
        if t.state==BEGAN then
            setup()
        end
    end
    
  • Posts: 815

    Thank you! This simple code is a beginning for a big Codea project!

Sign In or Register to comment.