angleToPointer on child sprite

Recommended Posts

Hi guys,

I'm trying to rotate a player's arm (anchored at the shoulder) to the mouse pointer using angleToPointer() method for aiming.  I have a player sprite and a frontArm sprite. angleToPointer works as expected until I make the frontArm sprite a child of the player sprite. When I do this, the frontArm sprite will get stuck at certain points and won't rotate any further. I'm a complete newbie to Phaser and game dev so any help would be appreciated. I'll put my code below:

	create: function() {
		this.background = this.game.add.sprite(0, 0, 'background');	
		this.player = this.game.add.sprite(200, 500, 'player', 'Fire Marshall Main_00025'); 

		this.frontArm = this.player.addChild(this.game.make.sprite(-10, -240, 'frontArm'));
		this.frontArm.anchor.setTo(0.48, 0.30);		

		//walk animation
		this.player.animations.add('walkright', Phaser.Animation.generateFrameNames('Fire Marshall Main_', 0, 24,'', 5), 24, true, false);
		this.player.animations.add('walkleft', Phaser.Animation.generateFrameNames('Fire Marshall Main_', 24, 0,'', 5), 24, true, false);

		cursors = this.game.input.keyboard.createCursorKeys();


	update: function() {
//player walk movement
 this.player.body.velocity.x = 0;
	if (cursors.right.isDown) {
        this.player.body.velocity.x = 150;
    }else if (cursors.left.isDown){
        this.player.body.velocity.x = -150;
        this. player.animations.play('walkleft');
    }else {
    	this.player.frame = 25; 

    this.frontArm.rotation = this.game.physics.arcade.angleToPointer(this.frontArm);



Share this post

Link to post
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.