Howdy, Stranger!

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

Physics object going through rotating chain

edited August 2014 in Questions Posts: 3

I'm just having a bit of trouble as when the chain is rotating fast, the ball object which is subject to gravity just goes right through it. I've tried physics.continuous and object.bullet but none of those seem to fix it? Any ideas?

Thanks

Comments

  • dave1707dave1707 Mod
    Posts: 6,963

    @Vince2225 The 2 things you tried should have worked. The only thing left is to show your code so we can try to see what's wrong.

  • dave1707dave1707 Mod
    Posts: 6,963

    @Vince2225 Have you tried sleepingAllowed=false. Not sure if that will help, but without code it's hard to find problems.

  • @dave1707 Sorry for the late reply but here's my code:

    function setup()
        supportedOrientations(LANDSCAPE_RIGHT)
        displayMode(FULLSCREEN)
        gameLevel = 0
        rectMode(CENTER)
    
        -- Physics Setup
        physics.continuous = true
    
        -- Level 1
        wall1 = physics.body(CHAIN, vec2(-200, 10), vec2(-200, -10), vec2(200, -10), vec2(200, 10), vec2(-200, 10))
        wall1.position = vec2(WIDTH/2, HEIGHT/2)
        wall1.sleepingAllowed = false
        wall1.bullet = true
    
    
        ball = physics.body(CIRCLE, 10)
        ball.x = WIDTH/2
        ball.y = HEIGHT-20
        ball.restitution = 0.2
        ball.gravityScale = 1
        ball.sleepingAllowed = false
        ball.bullet = true
    
    end
    
    -- This function gets called once every frame
    function draw()
    
        background(255, 255, 255, 255)
        sprite("SpaceCute:Background", WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
    
        if gameLevel == 0 then
    
            font("AmericanTypewriter-Bold")
            fill(0, 0, 0, 255)
            fontSize(50)
            text("Touch anywhere to start!", WIDTH/2, HEIGHT/1.5)
            sprite("Platformer Art:Guy Jump", WIDTH/2, HEIGHT/2.5)
    
        end
    
        if CurrentTouch.state == BEGAN then
            gameLevel = level1
        end
    
        -- Level 1
        if gameLevel == level1 then
    
            ellipse(ball.x, ball.y, 20)
    
            wall1.x = WIDTH/2
            wall1.y = HEIGHT/2
    
            translate(wall1.x, wall1.y)
            wall1.angle = Gravity.x*-90
            rotate(wall1.angle)
            rect(0, 0, 400, 20)
    
    
        end
    
    end
    
    
  • dave1707dave1707 Mod
    Posts: 6,963

    @Vince2225 I ran your code and see the problem you're talking about. When you use physics objects, you can't use any outside influence to directly control them. You're using Gravity to directly vary the angle of the wall which is causing your problem. You need to use Gravity to vary the physics "angularVelocity" of the wall. Go to the physics documentation and lookup angularVelocity. I think that should fix the problem. I don't have time right now, but I'll try some code later unless someone else gets to it first. See the link below for a similar game.

    http://codea.io/talk/discussion/4885/another-useless-game-#Item_6
    
  • dave1707dave1707 Mod
    Posts: 6,963

    @Vince2225 Here's your corrected code.


    supportedOrientations(LANDSCAPE_ANY) displayMode(FULLSCREEN) function setup() gameLevel = 0 rectMode(CENTER) -- Level 1 wall1 = physics.body(POLYGON,vec2(-200,10),vec2(-200,-10),vec2(200,-10),vec2(200,10)) wall1.position = vec2(WIDTH/2, HEIGHT/2) wall1.sleepingAllowed = false wall1.type=KINEMATIC ball = physics.body(CIRCLE, 10) ball.x = WIDTH/2 ball.y = HEIGHT-20 ball.restitution = .2 ball.sleepingAllowed = false ball.bullet = true end function draw() background(255, 255, 255, 255) sprite("SpaceCute:Background", WIDTH/2, HEIGHT/2, WIDTH, HEIGHT) if gameLevel == 0 then font("AmericanTypewriter-Bold") fill(0, 0, 0, 255) fontSize(50) text("Touch anywhere to start!", WIDTH/2, HEIGHT/1.5) sprite("Platformer Art:Guy Jump", WIDTH/2, HEIGHT/2.5) end -- Level 1 if gameLevel == level1 then ellipse(ball.x, ball.y, 20) wall1.angularVelocity=Gravity.x*-90 translate(wall1.x, wall1.y) rotate(wall1.angle) rect(0, 0, 400, 20) end end function touched(t) if t.state==BEGAN then gameLevel=level1 end end
  • @dave1707 I ran the corrected code but I want the angle of the object to be the angle of the iPad, not the angle of the iPad determines the velocity of which it turns in that direction. Is this possible?

    Thanks for the help

  • dave1707dave1707 Mod
    Posts: 6,963

    @Vince2225 I'm sure that's possible, but I'll be going to bed in a few minutes so it will be awhile before I can try it. Maybe someone will have an example before I get back to it.

Sign In or Register to comment.