Sacer

collide always false but triggers function permanently

Recommended Posts

hi there,

 

atm I'm trying to make an "robot unicorn attack" clone for my girlfriend and at the current state nearly everything works fine. I've got just one problem:

 

this.game.physics.arcade.collide(this.player, this.cloud, this.playerGrounded());

 

Is in my update-loop. obviously it's to check if the player hits a cloud where he could stand on. the function "playerGrounded()" resets my bool "grounded" to true and resets integer "jumpCount" to 0 (implented a double-jump).

 

My problem now is that console.log of collide of player and cloud just says "false" even though I can see in game that the player is standing on and "hitting" the cloud-object. But not just that: the function "playerGrounded" triggers permanently and with that resets the jumping vars which leads to unlimited jumps possible...

 

did I miss something with the collide? or is this a current bug from the latest github fork? (ME is running on my local system).

 

the physic settings of player object:

physics: 1

immovable: 0

gravity: 500

collideWithWorldBound: 0

mass: 1

bounce x/y: 0

 

... of cloud object:

physics: 1

immovable: 1

 

I wonder I had to set immovable to 1... if it's set to 0 the collide works but the cloud is pushed to the bottom of the canvas...

 

thx in advance for your help :)

 

PS: it would be realy helpful to have a ME-Documentation parallel to the phaser Doc. Just well may for future updates ^^

Share this post


Link to post
Share on other sites

Hi Sacer,

 

hard to tell if I don't see whole game. Have you tried to change function call this.playerGrounded() to reference to this function this.playerGrounded like this

this.game.physics.arcade.collide(this.player, this.cloud, this.playerGrounded);

Share this post


Link to post
Share on other sites

hi shmikucis,

 

thx for the reply.

 

well if I call this.playerGrounded nothing happens at all (collide still false) so the function is not triggered. if i call this.playerGrounded() it triggers the function permanently even if the collide says false. so the main problem is the collision. I can see the player standing on the cloud/platform. The player is touching it. But the function still gives me "false".

 

yeah erm here is my code so far for this problem (cleaned it up a bit)

"use strict";window.PonyUnicornAttack.state.play = {	preload: function(){		console.log("loading play state");	},		create: function(){		console.log("starting play state");		//creating gameobjects		this.bg = mt.create('bg');		this.bg2 = mt.create('bg');		this.bg2.x = this.bg.x + this.bg.width;		this.player = mt.create('pony');		this.firstCloud = mt.create('firstCloud');		this.cloud = mt.create('cloud');				//controls		this.space = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);		this.space.onDown.add(this.playerJumpCheck, this);				//animation stuff		this.player.animations.add('run', [4,3,2,1,0], 10, true);		this.player.animations.add('jump', [1], 10, false);				//game variables		this.bgSpeed = 500;		this.jumpVelocity = 450;				this.isGrounded = false;		this.jumpCount = 0;	},		update: function(){		//this.consoleLogs();		this.scrollBg();		this.moveClouds();		this.playerRun();		this.checkPlayerDead();						this.game.physics.arcade.collide(this.player, this.firstCloud, this.playerGrounded());		/*this.game.physics.arcade.collide(this.player, this.firstCloud, function(){			this.isGrounded = true;			this.jumpCount = 0;		});*/		//this.game.physics.arcade.collide(this.player,this.firstCloud, this.playerGrounded());		console.log(this.game.physics.arcade.collide(this.player, this.firstCloud));			},		scrollBg: function() {		this.bg.body.velocity.x = this.bgSpeed * -1;		this.bg2.body.velocity.x = this.bgSpeed * -1;		if((this.bg.x + this.bg.width) <= 0) {			this.bg.x = this.bg2.x + this.bg2.width;		}		if((this.bg2.x + this.bg2.width) <= 0) {			this.bg2.x = this.bg.x + this.bg.width;		}	},		moveClouds: function() {		this.firstCloud.x -= 1;		this.cloud.x -= 1;	},		playerRun: function() {		if(!this.jump) {			this.player.animations.play('run');		}	},		playerJumpCheck: function() {		console.log(this.jumpCount);				if(this.isGrounded && this.jumpCount < 2) {			this.isGrounded = false;			this.player.animations.play('jump');			this.jumpCount++;			this.applyVelocity();		}	},		applyVelocity: function() {		this.player.body.velocity.y = this.jumpVelocity * -1;	},		checkPlayerDead: function() {		if((this.player.y - this.player.height) > this.game.height) {			console.log("dead");			this.game.state.start("menu");		}	},		playerGrounded: function() {		this.jumpCount = 0;		this.isGrounded = true;		//console.log("grounded");	},		consoleLogs: function() {		console.log("grounded:" + this.grounded);		console.log("jumpCount:" + this.jumpCount);	}	};

Share this post


Link to post
Share on other sites

Hi, 

 

I've made an example which works http://mightyeditor.mightyfingers.com/#p2b8q/0-copy

// you have to make this.playerGrounded as reference without () and pass callbackContext this// collide(object1, object2, collideCallback, processCallback, callbackContext) → {boolean}this.game.physics.arcade.collide(this.player, this.firstCloud, this.playerGrounded, null, this);

And there was another bug

// you don't need this.isGrounded checkif(this.isGrounded && this.jumpCount < 2) {    this.isGrounded = false;    ...//insteadif(this.jumpCount < 2) {    this.isGrounded = false;    ...

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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.