Jump to content

jake142

Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by jake142

  1. Kind of solved. I set the anchorpoint to 0.0,0.0 of the ball and then rotated the ball around its own axis
  2. Got a bit further, but still not perfect. The script below makes the ball orbite the player, but I cant make it center the player. It orbites to much to the left/top of the player. Any ideas? Am I missing achorpoints or simliare? Anchor points are 0.5,0.5 for all sprites. //Calculate orbite of the ballvar _dx = this.endpoint.x-(this.x);var _dy = this.endpoint.y-(this.y);var oRad = Math.atan2(-_dy, _dx);if (oRad < 0) oRad += 2 * Math.PI; var angBet = oRad *180/ Math.PI+90; //Add 90 deg so that 0 degrees becomes "up"var oRad = Phaser.Math.degToRad(angBet); var newX = this.x + (_BALL_DISTANCE) * Math.sin(oRad);var newY = this.y + (_BALL_DISTANCE) * Math.cos(oRad);this.ball.body.x=newX;this.ball.body.y=newY;
  3. Hi, Im developing a turnbased football game with a ball and players. I developed a ball object extending a sprite and a player object extending a sprite. If you click a player you get an endpoint that you can drag around. When you press play the player will either run or shoot the ball in the direction of endpoint. My problem is that when I move around the endpoint Id like the player to rotate in the direction of the endpoint. This works, but if the player has the ball Id like that to rotate to (but the ball should more like orbite the player). Now the ball just rotates. I use this code to rotate the player (please dont ask me why I use +1.6 but otherwise the player doesnt follow my endpoint): this.rotation = game.physics.arcade.angleBetween(this, this.endpoint)+1.6; What I tried so far I've tried pivot but cant get that to work (dont ask me about the numbers ) this.ball.pivot.x = -1.8;this.ball.pivot.y = -0.1;this.ball.angle += 10;this.ball.angle = parseFloat(game.physics.arcade.angleBetween(this, this.endpoint)+1.57).toFixed(2)*100; I've tried to put the player and ball in a group. This works, but I run in to other problems when the ball should be shoot towards the endpoint and the player should stand still. game.physics.arcade.moveToXY(this,this.player.endpoint.x,this.player.endpoint.y,this.player.pass,0) The above code is part of my Ball object. It works if the player and ball is not in a group. If possible Id like to keep the ball and player as separate objects and not in a group. Anyone knows how I can get my ball to orbite around my player as the player rotates? Thanks
×
×
  • Create New...