Howdy, Stranger!

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

Psycics in codea

edited January 2015 in Examples Posts: 8

I have just read though the pdf, Codea for beginners - a really great learning source. I could use some more tutorials on how the psychics engine works. Are there any more good tutorials out there?

Comments

  • Posts: 8

    To be a little more specific of what i want to know: I want to know how it is possible to have a ball that jumps with different heights when bouncing off of two different surfaces. If that makes sense;)

  • dave1707dave1707 Mod
    edited January 2015 Posts: 7,522

    @Jell Here's an example of 2 balls bouncing off the bottom of the screen. The command that gives them different bouncyness is the restitution value. Try changing those values to see what happens. The smaller the value, the less bounce.

    EDIT:Code change to show 2 balls with the same restitution values bouncing off different surfaces with different restitution values.


    displayMode(FULLSCREEN) supportedOrientations(PORTRAIT_ANY) function setup() b1=physics.body(CIRCLE,40) b1.x=200 b1.y=900 b2=physics.body(CIRCLE,40) b2.x=500 b2.y=900 e1=physics.body(EDGE,vec2(0,0),vec2(WIDTH/2,0)) e1.restitution=.9 e2=physics.body(EDGE,vec2(WIDTH/2,0),vec2(WIDTH,0)) e2.restitution=.8 end function draw() background(40, 40, 50) fill(255) ellipse(b1.x,b1.y,80) ellipse(b2.x,b2.y,80) end
  • Posts: 8

    Yep i have understood that, but my question is to have just one ball, that bounces with two different heights when colliding with different surfaces.

  • dave1707dave1707 Mod
    Posts: 7,522

    @Jell You would then define 2 different surfaces and give them different restitution values.

  • Posts: 8

    Can you give a quick code example of that?:)

  • dave1707dave1707 Mod
    Posts: 7,522

    @Jell I changed the above code so both balls have the same restitution values, but the 2 surfaces have different restitution values. That will show the different bounce heights.

Sign In or Register to comment.