Search the Community

Showing results for tags 'velocity'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 53 results

  1. traxtrack

    Issue with Obstacle velocity

    Hello, I have an issue which keeps me stuck and I could not yet figure it out after being stuck for quite some time. I have a simple game in which obstacles ( spirtes of other cars) drop down from the top of the screen and I am trying to avoid those with my own car not to crash into them. The issue is that on some mobile devices the cars drop WAY faster than on my own device, I tested this from several different phones, the velocity differs depending on the phone, on some the obstacles drop faster on some they drop really slow. What oculd cause such an issue? I can provide code if it helps. Thanks,
  2. Hey, So I am working on a car game and I have 1 issue with the speed at which car drops. My friend who owns a IPhone s6 complains that on his device the cars drop too fast, while on my Samsung s7 edge the car seems to drop slow enough. I dont know what might cause it. My obstacle velocity is set to 1200; // OBSTACLES vars var obstacleSpeed = 1200; var obstacleDelay = 400; var platforms; var score; And this is my Loop + update function // OBSTACLES OF THE CAR game.time.events.loop(obstacleDelay, function(){ var obstacleSpeed = 1200; var obstacleDelay = 400; for(var i = 0; i < 1; i++){ if(game.rnd.between(0, 1) == 1){ var obstacle = new Obstacle(game, i); obstacle.scale.setTo(scaleRatio, scaleRatio); game.add.existing(obstacle); obstacleGroup.add(obstacle); } } }); // Game on touch move car game.input.onTap.add(function() { if (game.input.x < w / 2 ){ if( canMove && goleftonce == 2 || goleftonce == 1) { canMove = false; goleftonce++; gorightonce--; game.add.tween(car).to({ angle: -30}, 100, Phaser.Easing.Linear.None, true).onComplete.addOnce(function(){ game.add.tween(car).to({ angle: 0}, 100, Phaser.Easing.Linear.None, true); canMove = true; }, this); game.add.tween(car).to({x: car.x - w/3}, 100, Phaser.Easing.Linear.None, true); } } else { if( canMove && gorightonce == 2 || gorightonce == 1) { canMove = false; goleftonce--; gorightonce++; game.add.tween(car).to({ angle: 30}, 100, Phaser.Easing.Linear.None, true).onComplete.addOnce(function(){ game.add.tween(car).to({ angle: 0}, 100, Phaser.Easing.Linear.None, true); canMove = true; }, this); game.add.tween(car).to({x: car.x + w/3}, 100, Phaser.Easing.Linear.None, true); } } }); }, update: function() { // Collide the car and with the obstacles aka other cars game.physics.arcade.collide(car, obstacleGroup, function(){ canMove = true; countcars = 0; goleftonce = 2; gorightonce = 2; game.state.start('gameover'); }); } } // Position where the obstacle spawns Obstacle = function (game) { var position = game.rnd.between(0, 2); Phaser.Sprite.call(this, game, (w/3) * position + 130 , 0, "obstacle"); game.physics.enable(this, Phaser.Physics.ARCADE); }; Obstacle.prototype = Object.create(Phaser.Sprite.prototype); Obstacle.prototype.constructor = Obstacle; Obstacle.prototype.update = function() { this.body.velocity.y = obstacleSpeed; if(this.y > game.height){ countcars++; score.setText("Score: " + countcars); this.destroy(); } };
  3. Hello, I am making a kind of flappy bird. I want the pipes to move only horizontally. They have physics, so i can use the setVelocityX method. But they are falling down because of the gravity. I can change the position changing the x value of the pipe in the update method, but i would like to use the setVelocityX, it is more clear. var columna = this.physics.add.group(); ... columna.setVelocityX(-200); Thanks!
  4. How can I set the direction at which an object should be moving at in MatterJS physics? In Arcade physics I'd do `this.scene.physics.velocityFromRotation(angle, this.speed, this.velocity);`, but MatterJS doesn't seem to have a `velocityFromRotation` method.
  5. I'm trying to make my mesh smaller during its linear velocity movement. But unfortunately, as soon as I set the scaling, it stops the movement. How can I scale down my mesh in size without interrupting the movement? Is there an elegant way without having to calculate positions myself? See my example, where the movement stops after 1sec when trying to scale: http://www.babylonjs-playground.com/#5WEAFN
  6. I just upgraded to Phaser 2.9.3, since then I get a strange behavior. 1. I press Left / Right to change the Sprite's velocity (x). // See update method 2. Sprite has enabled Physics, World.gravity is 2000 // See in create method 3. But the Sprite instead of moving left (negative velocity.x) moves upwards // See attached gif What I figured out till yet: - velocity.y turn to NaN by colliding with a collisionGroup . - velocity.y stays NaN, even if the character moves into the air. (whyever it moves into air..) There is nothing else going on. I tested this as a test-case, not inside my game, to be sure I'm not messing something up. create method: super(state.game, x, y, 'minions'); this.level = state; this.anchor.setTo(0.5); this.game.physics.arcade.enable(this); this.game.add.existing(this); this.body.bounce.set(0.5); this.body.setSize(45, 110, 80, 45) update method: if(this.controls.on("left")) { this.body.velocity.x = -500; this.animations.play('walk'); } else if(this.controls.on("right")) { this.body.velocity.x = 500; this.animations.play('walk'); } Anyone have a clue why this happens? Thanks in advance.
  7. Hello, I have a sprite which has velocity.x=100 moving from {x:0; y: 200}. I need to set velocity.x=0 (e.g. stop sprite) once sprite reaches the coordinates {x:300; y:200}. How can it be done? I can't call collide function since there is nothing on that coordinates. I guess I need use the signal? Or any other solution? Thank you in advance. Any help will be appreciated.
  8. Chokitu

    Boost Velocity Phaser

    Hey everyone, I am really new to Phaser so If i ask something really stupid, I am sorry in advance, lol. I created an item named Redea that will boost the player speed for 15 seconds and change his sprites for 15 seconds, after that everything goes back to normal (this item will be activated when the player collides) I created the collision and everything but the speed is not changing and I can't seem to change the sprite, can anyone help me here?? That's what I got P.S The variable playerVelocity is because I was told that it can mess up with the physics if we tween the velocity. Btw, I need to make it only appear sometimes on the same spot, tho. Can anyone help me with that? redeaFun: function(){ this.emitter.x = this.redea.position.x; this.emitter.y = this.redea.position.y; this.emitter.start(true,500,null,15); this.playerVelocity = {x:0, y:0}; this.game.add.tween(this.playerVelocity) .to({y: 500,x:500}, 5,true); }, update: function() { this.player.body.velocity.x=this.playerVelocity.x; this.player.body.velocity.y=this.playerVelocity.y; }
  9. Please forgive the 'newbie' question... But... Can I always calculate a normalized value between -1 and 1 from the the current mesh moving velocity ??? The reason I ask.. I am creating blend tree support for animations (GOING GREAT SO FAR)... but the premise of all th docs for update the PosX and PosY comes from pumping the "User Input" horizontal and vertical input which will be -1 to 1... Which is Kool for when you are directly controlling the character, but lets say I am moving a character around thru AI and not using user input... I would like to just take the velocity at which I am moving (Which I can now easily get via my new Character Controller component I showed before) which may be larger than 1 because of all the speed and jumping force applied (I THINK ???) and 'normalize' that velocity x and y to -1 to 1 and feed the to the blend tree input as if it came directly from the user input axis device... That what mu Animation State component could just play the 'current movement' animation for both directly controlled and ai controlled movement... I think... dunno... What do you guys think ??? As Always, pinging @Deltakosh
  10. I see the docs of the Body class http://phaser.io/docs/2.6.2/Phaser.Physics.Arcade.Body.html But i am not sure which would be the right property to change. I have two balloons falling down and they might both at the same time or one after the other, hit my rectangle. The problem is, both objects stop moving after they hit the rectangle. i am sure this has to do something with physics. As if the vertical(y coordinate) velocity gets set to 0 when they hit the rectangle. Here is a sample code: graphics = si.gameObject.add.sprite(boxX, boxY, si.ImageAssetKeys.BALLOON_ANIM_ATLAS, 0); floatingAnim = graphics.animations.add('floating', si.GraphicsUtility.getFloatingAnimArray(), 30, true); splashAnim = graphics.animations.add('splash', si.GraphicsUtility.getSplashAnimArray(), 30, false); splashAnim.onComplete.add(si.LetterBox.splashComplete, this); graphics.animations.play('floating'); balloon.graphics = graphics; balloon.graphics.anchor.setTo(0.5, 0.5); balloon.graphics.body.checkCollision.up = false; balloon.graphics.body.checkCollision.left = false; balloon.graphics.body.checkCollision.right = false; balloon.graphics.body.checkCollision.down = true; balloon.graphics.body.velocity.y = velocity; balloon.graphics.allowGravity = false; balloon.graphics.allowRotation = false; Which body property should I change to prevent the stop in movement of balloons?
  11. I'm new to Phasor and using it to make a little game for my son with a firetruck driving around and spraying water to put out fires. When the space bar is pressed, the game creates individual water drop sprites coming from the truck with gravity turned on. I give the water drop velocity a slightly random component to make it spread out and not all follow a single parabola. There is a timed event to destroy each water drop. Here is a code snippet creating a water drop that is shooting to the right. drop = waterdrops.create(truck.body.position.x + TRUCK_SIZE1_X/2, truck.body.position.y - 20, 'waterdrop'); drop.frame = 0; drop.body.gravity.y = 300; drop.body.velocity.y = -100 + randn()*20 + truck.body.velocity.y/2; drop.body.velocity.x = 100 + randn()*20 + truck.body.velocity.x/2; game.time.events.add(WATERDROP_TIME, destroyDrop, this, drop); I fiddled around with different numbers until it looked like a nice spray of water coming out and hitting the ground. This works great when developing on my Macbook Air. However, the really weird issue is that when I run it on my Windows 7 machine the water only goes half as far before being destroyed. I tried doubling the delay time and this made it work well on windows 7 but then on the Macbook the water goes way too far. I also notice that the truck itself seems to go slower. It seems to me that if the body.velocity and body.acceleration values are scaled differently on each machine. My first though was that maybe it has to do with screen resolution, but thinking about it further that doesn't seem to make sense. So, why is there a difference in water drop behavior between the two platforms? Also, is there a better way to do what I'm trying to do here? As I said, I'm new to Phasor and this is just what I came up with after reading a few tutorials and looking at other examples. The game as it stands is hosted here -> http://drnx1m5jr5iqt.cloudfront.net/ Thanks! Ben ** UPDATE I ran the game on another Windows 7 machine and it works okay. So the problem seems to be with my older Windows 7 Machine. Could this be an issue of client side CPU processing capability? Does Phaser adjust frame rate to deal with slower computers?
  12. evilwizard

    Very strange collision behavior

    I made a pretty good Frogger clone using PhaserJS, but when refactoring the code, I ran into a very, very strange problem. My vehicles currently have a velocity of 200. When Frogger collides with one of them, that vehicle's velocity drops in half. Frogger also gains the velocity of that object. In update this.game.physics.arcade.collide(frogger, vehicles, this.loseLife); Here's my vehicles code objects.forEach(o => this.game.physics.arcade.enable(o)); [normalCar1, normalCar2, normalCar3, specialVehicle1, specialVehicle2, specialVehicle3, emergencyVehicle1, emergencyVehicle2, emergencyVehicle3].forEach(function(object) { object.body.velocity.x = object.direction == 'right' ? 200 : -200; }); Here is my loseLife() function loseLife: function() { /*switch (frogger.health) { case 5: lifeFive.destroy(); break; case 4: lifeFour.destroy(); break; case 3: lifeThree.destroy(); break; case 2: lifeTwo.destroy(); break; case 1: lifeOne.destroy(); break; }*/ frogger.damage(1); gameState.resetPosition(); gameState.resetRows(); /*if (!frogger.alive) { clearInterval(sinkLillies); game.state.start('gameover'); }*/ }, The important method here is resetPosition() which moves Frogger back to the starting position resetPosition: function() { frogger.alpha = 0; frogger.x = this.game.world.centerX; frogger.y = this.game.world.height - 18; game.time.events.add(1000, function() { this.game.timer = 50000; frogger.alpha = 1; }, this); }, The important thing here is that I do not specify that I want the velocity to increase Hopefully, a video will make it easier to understand https://webmshare.com/DmoAQ Edit: A temporary working solution I was able to "solve" this by adding this line in the resetPosition() function frogger.body.velocity.x = 0; And to remove that weird behavior of the car slowing down objects.forEach(function(object) { this.game.physics.arcade.enable(object); object.body.immovable = true; }); This is a hack though. I shouldn't have to explicitly add these lines, because collisions shouldn't cause this behavior in the first place.
  13. crffty

    velocity to 0

    hello. I'm trying to stop my endless runner upon collision between the player and an 'obstacle' to do this i would like to stop the sprits form moving. velocity = 0. I can't work out how to do this though. thoughts? help? advice? beer? vaultage.game = function() {}; vaultage.game.prototype = { create : function() { // physics engine this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; // background this.background = this.game.add.tileSprite(0, 0, this.game.width, 360, 'background'); this.background.autoScroll(-100, 0); // ground this.ground = this.game.add.tileSprite(0, 290, this.game.width, 8, 'ground'); this.ground.autoScroll(-400, 0); // player this.player = this.add.sprite(45, 200, 'player'); this.player.animations.add('run'); this.player.animations.play('run', 15, true); // obstacles this.obstacles = this.game.add.group(); this.obstacles.enableBody = true; // physics on sprites this.game.physics.arcade.enable([this.player, this.ground]); this.ground.body.immovable = true; this.ground.body.allowGravity = false; this.player.body.collideWorldBounds = true; // run the functions to create obstacles this.createObstacles(); this.nextObstacle(); }, update : function() { // look for collisions between sprites this.game.physics.arcade.collide(this.player, this.ground); if (this.game.physics.arcade.collide(this.player, this.obstacles)) { this.endGame(); }; // run the updateObstacle function for each obstacle this.obstacles.forEachAlive(this.updateObstacle, this); }, shutdown : function() { }, createObstacles: function() { // 1 x 5 keys == 5 obstacles this.obstacles.createMultiple(1, 'obstacle', [0, 1, 2, 3, 4]); this.obstacles.setAll('body.allowGravity', false); this.obstacles.setAll('body.immovable', true); }, nextObstacle: function() { // timer on next obstacle spawn this.resetNextObstacle(); this.time.events.add(this.rnd.between(750, 2000), this.nextObstacle, this); }, resetNextObstacle: function() { // reset each obstical to be re-used var obs = this.obstacles.getFirstDead(); // location of re-set dead obsticals if (obs) { obs.reset(); obs.left = this.world.bounds.right; obs.bottom = this.ground.top; obs.body.velocity.x = -400; } else { console.warn("None available", this.obstacles.children); } }, updateObstacle: function(obs) { // kill obstacle after it moves out of bounds if (obs.right < this.world.bounds.left) { obs.kill(); } }, endGame: function() { this.ground.autoScroll(0, 0); this.background.autoScroll(0, 0); this.obs.body.velocity.x = 0; } } thank you for your time and patients I'm still learning and its all a bit over my head sometimes. any advice would be greatly appreciated.
  14. Greetings, I was looking the forum for an answer, but wasn't able to find even the issue. Maybe it's just my wrong usage of Phaser mechanics. Anyway, I'll be gratefull for any information. The matter: I got two separate files ("game.js" and "player.js"). While game.js used as a "state", player.js is just an attached library with some functions. There is hotkey binding in player.js, which is called in game.js within "update" property. You know, to make an object move around. But when the hotkey is pressed, there are from 60 to 150 identical assignments happens. It is about 100 times more on the average than is needed. Question: Is there a solution to make just one assignment? Additional information: I'll try to explain the whole structure in few words. In "game.js" there is variable with object ePow = { x: 100*(settable int), y: 100*(settable int), currentX: 0, currentY: 0 } It is called within "creaton" property of game.js from player.js's another prototype, but I think it isn't important. In "player.js" there is prototype "keybind", which contains creation of hotkeys, listeners for hotkeys and assignment functions. Points of interest within keybind: 1. this.(game.js's context with sprite object).velocity.x = (game.js's context).ePow.currentX; 2. function thrustLeft () { (game.js's context).ePow.currentX = (game.js's context).ePow.x * -1; 3. this.(hotkey).onDown.addOnce(thrustLeft); When hotkeys is pressed console shows me, that value was assignet for 127 times, for example. Help
  15. Hi friends, I'm very new to Phaser (but I have a long programming background) and right now I'm trying to work on a new game concept of mine. Basically, it is a regular Pong but with few twists. I have attached an image below of the main game for further clarifications. gifs upload 1) As you can see, the shape of the paddles is a polygon. As such, I have to use P2 physics for them as the simple arcade won't suffice because of their peculiar shape. 2) Now since the paddles are using P2, I'm forced to use P2 for the ball as well because they both need to collide and I can't collide a P2 and Arcade sprite 3) Now the problem is, when I apply a velocity to the ball and make it move at a specific direction, I want it to collide with the body ahead (either one of the paddle or wall) and continue on it's path with the SAME velocity infinitely . Right now, it slows down momentarily till it comes to a full stop. I can achieve this 'continuous velocity' for the ball when it is in arcade but I can't use arcade since my paddles are P2 and so I"m forced to find a method to achieve this in P2 for the ball. My Ball sprite code is : this.Ball = this.add.sprite(this.world.width / 2, this.world.height / 2, 'Ball') this.physics.p2.enable(this.Ball); this.Ball.body.clearShapes(); this.Ball.body.loadPolygon('physicsData', 'Ball'); this.Ball.anchor.setTo(0.5, 0.5) this.Ball.checkWorldBounds = true; this.Ball.body.collideWorldBounds = true; this.Ball.body.mass = 0.01 this.Ball.body.restitution = 1 this.Ball.body.damping = 0 this.Ball.body.velocity.x = 400*(Math.cos(0)); this.Ball.body.velocity.y = 400*(Math.sin(0)); Thank you and warm regards
  16. for(i=0;i<arr.length;i++) { a=index of i in arr; if(a=="moveRight") { image.body.velocity.x=150; } if(a=="moveDown") { image.body.velocity.y=150; } } when arr[0]=='moveRight' and arr[1]=='moveLeft' it looks like the image moves diagonally but I want only one to work at once. What should I do here now?
  17. So I have a game, where movement and collision are big aspects. Currently I have a system where when a client say presses "W", body.velocity of their sprite is set to +150 in the x plane. Previously, my system for the multiplayer side of the game in terms of movement was when the player moves on the client side, send his new x & y position to the server. This was a great system, until I started turning the server into an authoritative one to prevent against hackers who could speed hack and set their own positions. My new system is whenever a player hits "W" send to the server that this person is hitting W and then server calculates the players position (say adding 4 pixels for every W call to the players last position) and saves it on the server side. (Basically movement is on the server now). Now this is where it gets a bit hairy. Since I dont wait to get a response back form the server to move the player on the client side (bc that would cause terrible ping issues), whenever the player hits W, his REAL position (on the server) is calculated and saved to send to other players, and his "client position" the one that could potentially be hacked to move faster or teleport other places, is also moved just so i dont have to deal with ping issues. P.S This position is useless, it can be hacked or changed all it wants lol. Now this new system leads me to the following problem. The issue with this new system is whenever i set the velocity of the client sided sprite, its speed doesn't correlate with the server, since on the server I have to move the player based on if they are hitting a key or not, and there is no way for me to know how long they are holding the key, I cant use velocity on the server, only say moving the persons position 4 pixels every call of "W". However if i say switch to this system on the client, of setting a position 4 pixels away everytime they press W, instead of changing the velocity, I can sync up the client and server position perfectly. Butttt this creates the problem that my sprite can no longer collide with things because it is teleporting everywhere essentially. So Im stuck lol. Anyone have any ideas of how to handle this? Is there possibly a way i could do collision without velocity being set? Thanks for any help and sorry for poor language and bad grammar lol. Im insanely tired and just want some sleep rn
  18. Code4Breakfast

    Boss Movement Method

    I am working on a boss movement method. The idea is that every 8 seconds the method will be called from the create method, this may be part of the problem... The idea is that every 8 seconds the method will be called. The boss will appear from one side of the screen and exit to the other. The bosses y coord will be based on where players y coord. The issue I am running into is that when the level starts the boss starts moving before 8 seconds goes across the screen to exit and is never seen again. I am not moving the player during the test so the bird isn't going beyond the y screen parameters. The console is only logging the side once so it only seem to be getting called once. My relevant code below: // inside the create method this.blueBirds = this.add.group(); this.blueBirds.enableBody = true; this.multiBlueBirdFlight = this.game.time.events.loop(Phaser.Time.SECOND * 8, this.flyBlueBird(), this); // inside the game state flyBlueBird: function () { var blueBird = this.blueBirds.getFirstExists(); if (!blueBird) { blueBird = this.blueBirds.create(this.X_MIN, this.player.y -100, 'blueBird'); blueBird.anchor.setTo(0.5); blueBird.customParams = {}; blueBird.customParams.side = 'left' blueBird.body.allowGravity = false; blueBird.animations.add('flying', [0,1,2,3], 5, true); } if (blueBird.customParams.side == 'left') { blueBird.reset(this.X_MIN , this.player.y - 100) blueBird.body.velocity.x = 100; blueBird.body.velocity.y = -10; blueBird.customParams.side = 'right'; } else { blueBird.reset(this.X_MAX + 50, this.player.y - 100); blueBird.body.velocity.x = -100; blueBird.body.velocity.y = -10; blueBird.customParams.side = 'left'; } blueBird.play('flying') console.log(blueBird.customParam.side) }
  19. deedeekaka

    Sticky collisions in Arcade physics

    I am building a basketball game. I cannot get the ball to stop sticking to the rim colliders. When I was running p2 physics, the ball would simply bounce off the rim colliders as expected, but now, everytime the ball touches the rim colliders, it slows down movement rapidly and doesn't bounce or fall as expected. I think I might be missing a property setting somewhere. I set the rim colliders (leftMarker + rightMarker) to be immovable in create() but I'm not sure what else I need. I don't understand why the colliders stick to each other! Any help is appreciated! Basketball.Game = function (game) { this.score = null; this.scoreText = null; this.ball = null; this.net = null; this.basket = null; this.rim = null; this.leftMarker = null; this.rightMarker = null; this.checker = null; this.ballCollisionGroup = null; this.rimCollisionGroup = null; this.collisionsOn = false; this.launched = false; this.respawned = false; this.lastPointerPos = null; //HTML element that will produce screenshot this.clickToSave = null; //Constants this.GRAVITY = 1600; this.SHOOT_FORCE = 1400; this.EDGE_CUSHION = 10; this.SCALE_PERCENT = 0.55; }; Basketball.Game.prototype = { create: function () { //Initialize physics world this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = this.GRAVITY; //Create basket group this.basket = this.game.add.group(); //Load net sprite this.net = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY - 200, 'net'); this.net.anchor.setTo(0.5); this.basket.add(this.net); //Load hoop markers this.leftMarker = this.game.add.sprite(this.game.world.centerX - 57, 232, 'marker'); this.rightMarker = this.game.add.sprite(this.game.world.centerX + 57, 232, 'marker'); this.leftMarker.anchor.setTo(0.5); this.rightMarker.anchor.setTo(0.5); this.basket.add(this.leftMarker); this.basket.add(this.rightMarker); //Load ball sprite this.ball = this.game.add.sprite(this.game.world.centerX, this.game.world.height - 100, 'ball'); this.ball.anchor.setTo(0.5); //Load rim sprite this.rim = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY - 200, 'rim'); this.rim.anchor.setTo(0.5); this.basket.add(this.rim); //Load checker sprite this.checker = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY - 80, 'checker'); this.checker.anchor.setTo(0.5); this.basket.add(this.checker); //Setup physics this.game.physics.arcade.enable([this.leftMarker, this.rightMarker, this.ball]); this.leftMarker.body.setCircle(this.leftMarker.width / 2); this.rightMarker.body.setCircle(this.rightMarker.width / 2); this.leftMarker.body.moves = false; this.rightMarker.body.moves = false; this.leftMarker.body.immovable = false; this.rightMarker.body.immovable = false; this.leftMarker.body.enable = false; this.rightMarker.body.enable = false; this.ball.body.setCircle((this.ball.width * this.SCALE_PERCENT) / 2); this.ball.body.allowGravity = false; this.ball.body.bounce.set(0.8); this.ball.body.velocity.set(0); //Enable input this.game.input.onDown.add(this.track, this); this.game.input.onUp.add(this.launch, this); //Initialize this.score = 0; this.scoreText = this.game.add.bitmapText(this.game.world.centerX, this.game.world.centerY, 'pixel', 'Score: ' + this.score, 36); this.scoreText.anchor.setTo(0.5); this.lastPointerPos = new Phaser.Point(0, 0); //For mobile Phaser.Canvas.setTouchAction(this.game.canvas, 'auto'); this.game.input.touch.preventDefault = true; }, update : function () { this.game.physics.arcade.collide(this.ball, this.leftMarker); this.game.physics.arcade.collide(this.ball, this.rightMarker); //Only enable collisions when the ball is above the net markers if (this.ball.y < this.basket.children[1].y - this.ball.height / 2) { console.log("Detect collisions!"); this.leftMarker.body.enable = true; this.rightMarker.body.enable = true; } //Check if the ball is out of bounds if (this.ball.x < this.camera.x - this.ball.width / 2 || this.ball.x > this.camera.width + this.ball.width / 2|| this.ball.y < this.camera.y - this.ball.height / 2 || this.ball.y > this.camera.height + this.ball.height / 2) { //Respawn the ball if it hasn't already if (!this.respawned) { this.respawn(); } } }, render : function () { this.game.debug.body(this.ball); if (this.leftMarker.body.enable) { this.game.debug.body(this.leftMarker); this.game.debug.body(this.rightMarker); } }, track : function () { //Update the last finger position this.lastPointerPos.x = this.input.x; this.lastPointerPos.y = this.input.y; //Set the ball physics to be still this.ball.body.allowGravity = false; this.ball.body.velocity.set(0); this.launched = true; }, launch : function () { //Launch the ball if it hasn't already if (this.launched) { this.game.add.tween(this.ball.scale).to({ x: this.SCALE_PERCENT, y: this.SCALE_PERCENT }, 1000, Phaser.Easing.Linear.Out, true); this.launched = false; this.ball.body.allowGravity = true; //Get the direction of finger swipe, normalize it, and apply a scalar to the velocity of the ball var direction = new Phaser.Point(this.input.x - this.lastPointerPos.x, this.input.y - this.lastPointerPos.y); Phaser.Point.normalize(direction, direction); if (direction.y < 0) { this.ball.body.velocity.x = direction.x * this.SHOOT_FORCE; this.ball.body.velocity.y = direction.y * this.SHOOT_FORCE; } } }, respawn : function () { this.respawned = true; //Set the ball physics to be still again this.ball.body.allowGravity = false; this.ball.body.velocity.set(0); //Disable collisions this.leftMarker.body.enable = false; this.rightMarker.body.enable = false; this.game.time.events.add(Phaser.Timer.SECOND * 0.25, function () { this.respawned = false; //Rescale the ball and its body this.ball.scale.setTo(1); this.ballResized = false; //Spawn the ball in a new, random location var ballSpawnX = this.game.rnd.integerInRange(this.camera.x + this.ball.width / 2 + this.EDGE_CUSHION, (this.camera.width - this.ball.width / 2) - this.EDGE_CUSHION); ballSpawnX = this.game.math.snapTo(ballSpawnX, 10); //Make sure the ball is in the boundary we set if (ballSpawnX < this.ball.width + this.EDGE_CUSHION) { ballSpawnX = this.ball.width + this.EDGE_CUSHION; } else if (ballSpawnX > this.world.width - this.EDGE_CUSHION) { ballSpawnX = this.world.width - this.EDGE_CUSHION; } this.ball.x = ballSpawnX; this.ball.y = this.game.height - 100; }, this); }, saveCanvas : function () { var link = this.game.canvas.toDataURL('image/png'); window.open(link, '_blank'); } };
  20. Hi Guys, I've come across a problem with p2 body. I have 2 sprite, sprite1 is physics enabled, and sprite2 is create a Phaser.Physics.P2.Body They will be moving using velocity after 2 seconds, but sprite2 not working... I made a JsFiddle to explain my question. https://jsfiddle.net/pbq93enn/ Does anyone have an idea what I'm doing wrong? Thanks in advance!
  21. Hello! I just want to make sure there is nothing I am missing before reporting this as a bug. I've created a small test case where a ball go through a wall although it shouldn't because there is the `collide` between the two body materials. I've tried playing with the contactMaterial options without any success. Everything is fine but as a certain velocity where it go through. For instance, if you change the x velocity value to 650, the ball will not go through. Here is the JSFiddle example: https://jsfiddle.net/ygk5dcw4/ I've put a debugger on the "console.log('it overlaps!!!');" on the first occurrence and debugged a bit and the "runNarrowphase" method will return that there is no collision between the ball and the wall. Although, on the second occurrence, the same method returns a collision. Please let me know if I am doing something wrong before I post this as a bug. Thank you very much!
  22. I have a p2 Object with the following properties this.game.physics.p2.enable(this.player, true); this.player.body.clearShapes(); this.player.body.loadPolygon('playerPolygon','player'); this.player.body.allowRotation = false; this.player.body.fixedRotation = true; this.player.body.immovable = true; this.player.body.setCollisionGroup(playerCollision); this.player.body.collides(ballCollision); this.player.body.kinematic = true; this.player.body.data.shapes[0].sensor = false; this.player.body.collideWorldBounds = true; The above object can only move along its X axis and I want to trigger push/ hit force to its impacting object on collision this.game.physics.p2.enable(this.ball); this.ball.body.setCircle(28); this.ball.body.collideWorldBounds = true; this.ball.body.allowRotation = true; this.ball.body.fixedRotation = false; this.ball.body.adjustCenterOfMass(); this.ball.body.setCollisionGroup(ballCollision); this.ball.body.collides(playerCollision); The above object is always the impacting object whose movement is controlled by gravity and impulse. I'm trying to figure out how to calculate the following:- The point of collision on the body of "this.player" The impulse to apply to the impacting object after collision to simulate a proper/ accurate deflection setting the projected angle and speed/ velocity what properties of the impacting object do I set? Force? AngularVelocity? Velocity?
  23. GaryS

    Calculate velocity

    Please excuse what I'm sure is a very novice question, but I've been all over Google and I can't find what I'm looking for. I'm attempting to detect when a sprite is no longer being moved by the player - e.g. when the player releases the key. I'd like to do this by seeing how the sprite is moving, rather than relying on detecting the keypress or other input, as the sprite has some drag associated with it and I'd like to play a 'slowdown' animation as the drag slows the sprite. I'm also attempting to keep as much encapsulated in my prefab as possible and thus I don't want to put anything in the main game's update method to initiate the slowdown function. So, what I'd like to do is detect that the sprite is no longer moving at the veliocity I'd expect it to if the move functions were being called... The thought being that the velocity is constant while the key is down, and begins to reduce when the key is released - however because the sprite can be at any angle, I can't predict what the velocity will be without understanding how it's calcuated. So, unless someone has another suggestion as to how I might detect that the sprite is slowing down, in any direction - would someone be able to give me some schooling in what I assume is very basic trigonometry? Thanks!
  24. vmars316

    bullets.body.velocity.

    Hello & Thanks : I am having trouble getting bullets to go : I get error :Uncaught TypeError: Cannot read property 'velocity' of undefined m-vertical-collision.js:124 Pls , what do I need to make this puppy go ? Thanks
  25. Hello everybody ! I'm trying to build some slope and non-regular tiles but i have a lot of problem with collision. The main problem is that when I use moveRight()/moveLeft() on a slope (in this case, just a simple body) and I stop at the middle of the tile, my player just jump like that : On the other case, when I from the top of the tile to the left, my player just fly in the air and slowly land. I tried to tweak a bit the material by setting friction and removed restitution but it don't really change. Maybe it could work if I put a huge amount of gravity but then it will influence other part of the game (like jumping). I have also tried to add a sensor (simple circle) just below the sprite so I could set the x/y velocity at zero when the sensor is in contact with the ground. This is working well but it's not working at all when i'm trying to go down the slope. Basically it moves one px left, set velocity to 0, fall one px (cause of the gravity). move one px left and etc... This is the code if you want to reproduce the problem (I'm stuck with this for many days D:) : create() { this.playerMaterial = this.game.physics.p2.createMaterial() this.tileMaterial = this.game.physics.p2.createMaterial() this.game.physics.startSystem(Phaser.Physics.P2JS); this.game.physics.p2.gravity.y = 400 this.player = this.game.add.sprite(40,40, 'player', 1) this.tile = this.game.add.sprite(80, 272, 'player') this.tile.visible = false this.game.physics.p2.enable([this.player, this.tile]) this.player.body.clearShapes() this.player.body.addRectangle(0, 40, 0, 0) this.player.body.debug = true this.player.body.fixedRotation = true this.player.body.setMaterial(this.playerMaterial) this.player.body.mass = 1.5 this.tile.body.clearShapes() this.tile.body.addPolygon( {} , 0,29, 0,40 , 50, 40 , 50, 0 ) this.tile.body.debug = true this.tile.body.static = true this.tile.body.setMaterial(this.tileMaterial) this.cursors = this.game.input.keyboard.createCursorKeys() this.jumpButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR) let contactMaterial = this.game.physics.p2.createContactMaterial(this.playerMaterial, this.tileMaterial) contactMaterial.friction = 1 contactMaterial.restitution = 0 contactMaterial.frictionRelaxation = 3; contactMaterial.surfaceVelocity = 0 contactMaterial.frictionStiffness = 1e7; contactMaterial.stiffness = 1e7; } update() { if (this.cursors.left.isDown) { this.player.body.moveLeft(200); } else if (this.cursors.right.isDown) { this.player.body.moveRight(200); } else { this.player.body.velocity.x = 0; } if (this.jumpButton.isDown) { this.player.body.moveUp(100); } } So, any idea how can I resolve this problem ? I'm a bit lost. Thanks !