Jump to content

Lock rotation revolute constraint


hoomersinpsom
 Share

Recommended Posts

How can i lock the angle between two sprites which have a revolute constraint atached to each other? Example i have a arm atached to a body with a revolute constraint and i want to that arm keep up at certain angle, i cant reproduce this : (

 

'use strict'
game = new Phaser.Game(320, 480, Phaser.AUTO, 'space')

mainState =
  preload: ->
    game.load.image('body', 'public/images/body.png')
    game.load.image('arms', 'public/images/arms.png')
    game.load.image('ground', 'public/images/ground.png')
  create: ->
    game.physics.startSystem(Phaser.Physics.P2JS)
    @chest = game.add.sprite(29,53,'body')
    @arms  = game.add.sprite(8,53,'arms')
    @ground  = game.add.sprite(320,70,'ground')
    game.physics.p2.enable([@chest, @arms, @ground])

    robotCollisionGroup = game.physics.p2.createCollisionGroup()
    environmentCollisionGroup = game.physics.p2.createCollisionGroup()

    @ground.body.static = true
    @ground.body.setCollisionGroup(environmentCollisionGroup)
    @ground.body.collides(robotCollisionGroup)

    @chest.body.debug = true
    @chest.body.setCollisionGroup(robotCollisionGroup)
    @chest.body.collides(environmentCollisionGroup)

    @arms.body.debug = true
    @arms.body.setCollisionGroup(robotCollisionGroup)
    @arms.body.collides(environmentCollisionGroup)

    @ground.reset(game.world.centerX, game.world.height)
    @chest.reset(game.world.centerX, game.world.height - 100)
    @arms.reset(game.world.centerX, game.world.height - 100)

    game.physics.p2.gravity.y = 600

    @chest.body.collideWorldBounds = true
    @arms.anchor.setTo(0.5, 0.5)
    @constraint = game.physics.p2.createRevoluteConstraint(@chest, [ -14, -26.5 ], @arms, [ 0, 28])
    
    @cursors = game.input.keyboard.createCursorKeys()
  update: ->
    if @cursors.left.isDown
      @arms.body.rotateLeft(60)
    else if @cursors.right.isDown
      @arms.body.rotateRight(60)
    else
    return
  render: ->
    game.config.enableDebug = true
    game.debug.spriteInfo(@arms, 32, 32)

# Bootstrap
game.state.add('start', mainState)
game.state.start('start')

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...