Jump to content

Lock rotation revolute constraint


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: ->
    @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

    @chest.body.debug = true

    @arms.body.debug = true

    @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
    else if @cursors.right.isDown
  render: ->
    game.config.enableDebug = true
    game.debug.spriteInfo(@arms, 32, 32)

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


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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