Game Development Community

collision doing weird stuff

by Aleksandar Sandic · in Torque Game Builder · 10/02/2010 (6:19 pm) · 0 replies

I want to make a platformer with Super Mario like controls. Since the existing platformer controls behaviours are buggy and seem kind of bloated, I sat down to write my own from scratch. Movement works fine, but weird things happen, when I bump into a wall.

This is, what my scene looks line:
img15.imageshack.us/img15/3576/screenshot20101002at753.png
I use scene objets as walls and the tiles are just for the look. Both scene objets are set to only receive collision and their response is "clamp".
Walking and jumping on the floor works just fine. But when I'm in mid-air and hit the wall, while holding left, my character's vertical movement starts slowing down until it comes to a halt. Imagine sliding something over the floor, it will slow down and stop eventually. Except here it is sliding on the wall. Whether it slides up or down depends on the direction, it had when touching the wall. So if i was falling, I would keep falling slower and slower.
However, once I release he left button, the ninja acts normally again.

The Other thing is when standing in the left corner on the ground. If I keep pressing left, and then jump, the Ninja jumps twice as high. The exact same thing happens if I jump in mid-air (I haven't yet disabled that) while pressing left against the wall. Releasing left brings him back to normal jumping (even, if he was in a prolonged jump).

The player's collision setting are "send physics" and "send collision"
img291.imageshack.us/img291/592/screenshot20101002at808.png
This is the part of my behaviour responsible for the controls:
unction myPlatformerControlsBehavior:: moveLeft(%this, %val){
	if(%val == 1){ //called when pressing the button
		%this.left = 1; //we are walking left
	} else{
		%this.left = 0; //in this case we are not walking left
	}
}

function myPlatformerControlsBehavior:: moveRight(%this, %val){
	if(%val == 1){
		%this.right = 1;
	}else{
		%this.right = 0;
	}
}

function myPlatformerControlsBehavior:: jump(%this, %val){
	//nothing should happen if either the player is already in mid-air or the button was released
	if(%val == 0)
		return;
	//if(%this.airborne)
	//	return;
		
	%this.jump = 1;
	%this.airborne = 1;
}

function myPlatformerControlsBehavior:: updateMovementX(%this){
	//determine the movement direction and speed
	%newSpeed = (%this.right - %this.left) * %this.runSpeed;
	//set the speed
	%this.owner.setImpulseForce(%newSpeed, 0);
	
	//just so we can observe the speed for experimental purpose
	//echo("unaltered speed:" SPC %this.owner.getLinearVelocityX());
	
	//The character starts out too slow, so let's give him a small boost
	if(%this.right + %this.left == 1 && mAbs(%this.owner.getLinearVelocityX()) < %this.minStartSpeed)
		%this.owner.setLinearVelocityX((%this.right - %this.left) * %this.minStartSpeed);

	//it takes him forever to stop, so let#s just cut it here.
	if(%this.right + %this.left == 0 && mAbs(%this.owner.getLinearVelocityX()) < %this.minStopSpeed)
		%this.owner.setLinearVelocityX(0);
	
	//echo("corrected speed:" SPC %this.owner.getLinearVelocityX());
}

function myPlatformerControlsBehavior:: updateMovementY(%this){
	if(%this.jump == 1){
		%this.owner.setLinearVelocityY(-%this.jumpSpeed);
		%this.jump = 0;
		//%this.airborne = 1;
	}
	//echo("Airborne?" SPC %this.airborne);
}
I used setImpulseRoce rather than setLinearVelocityX because it has this nice effect of acceleration and slowing down. All the problems still occur, if I use setLinearVelocityX instead, too.
In terms of collision, no scripting at all has been done.

i hope, someone can help, this thing is driving me crazy.