Author Topic: [2.43]platform game collision unstable at certain height  (Read 1768 times)

deadkidsong

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Hi,

I had just set up the basic flixel platform/jumper game. I am using tile set of each block of 16*16. Everything's fine then I found camera shaking when the player is at certain height(504). Logging the player.y, saying it's 504 or 504.0000000006 or 503.9999999994.(Exactly these numbers no others) And camera loyally follows player causing shake. So, its collision solving's part. But things are fine at any other height.

I tidy up my swf to regenerate the thing. X to jump, C to log current position to console(~).
You will fall down to the right height. My FP is 10.2, with Flixel 2.43, not a chance to test other combinations yet..

Sometimes it wont shake, sometimes longer, sometimes shorter, but the numbers will always be strange.

Please help.

the swf
http://www.mediafire.com/?e969mbbgrp9benf
(cant use the attachment for some reason)

this is the simple code for the state
Code: [Select]
package FlxSys
{
import FlxSys.Char.TestPlayer;
import org.flixel.*;

/**
* ...
* @author La
*/
public class ShakeBugState extends FlxState
{

[Embed(source = '../../asst/mainTile_0.png')]
private var mainTile_0:Class;

[Embed(source = '../../asst/spaceman.png')]
protected var PlayerImage:Class;

[Embed(source='../../asst/mapCSV_solid_shake_bug.csv', mimeType='application/octet-stream')]
protected var data_shakeBug:Class;

public var player;

public var solidMap:FlxTilemap;//the only tile map deal with wall/floor collision, inside g_solid
public var g_solid:FlxGroup;

public function TestState()
{

}

override public function create():void
{
bgColor = 0xFF92DEF8;
//FlxG.showBounds = true;
//FlxG.mouse.show();
//Mouse.show();


//================
g_solid = new FlxGroup();
solidMap = new FlxTilemap();
solidMap.loadMap(new data_shakeBug, mainTile_0, 16, 16);
g_solid.add(solidMap);


//================
//
player = new TestPlayer();
player.loadGraphic(PlayerImage, true, true, 8, 8, false);
g_solid.add(player);

add(g_solid);

}

public override function update():void
{
super.update();
FlxU.collide(solidMap, player);
FlxG.follow(player, 2.5);
//FlxG.followAdjust(1, 0.0);
FlxG.followBounds(0, 0,800,800);
}

}

}

Wing Eraser

  • Guest
First fix this:
Code: [Select]
FlxU.collide(solidMap, player);
FlxG.follow(player, 2.5);
//FlxG.followAdjust(1, 0.0);
FlxG.followBounds(0, 0,800,800);

Put it in the create()!

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
I've run into this problem quite a few times. The problem is that at some values, with velocity and collision it will alternate your players coordinates back and forth between values right around an integer (504.0000000006 and 503.9999999994 in your case), possibly because of rounding errors. Somewhere along the line of the camera logic, it sets your cameras position to your character, and then it floors the coordinates before it draws. Because of this, the camera is getting its position altered between 504 and 503, causing the shake.

The way I changed this was change the 2 floors to rounds (because with tile sizes being integer values, you won't have the problem with alternating between values such as 504.5000006 and 504.49999996, so round shouldn't cause you these errors).

Another way might be to make your camera not move towards the player unless the player is more than X pixels away, but this requires more custom logic.

@Wing Eraser: What do you mean by moving those to the create method? The collide definitely needs to be in update (otherwise you'll collide once on creating the level, but then no more collision?), and I know for some things (my current project included), you want the camera follow to be there too (depending on how your camera is set up, whether you need it exactly on the object every frame, etc). Unless you mean put it in create AND update, then maybe...

deadkidsong

  • Member
  • **
  • Posts: 42
  • Karma: +0/-0
    • View Profile
Thanks guys!


I tried Wing's advise but just the camera stuff moved to create() (or no collision), and it seems that I had been using the camera in a wrong way, because only when put into create(), had I felt the camera lag. And it dose not shake(which I will test more).But the numbers are still strange(504.00006/503.999999994).

I think is also the camera's problem, as Arkeus posted. The story is: somehow collision solving gives wield output (504.00006/503.999999994) and when putting the follow() in update(), camera will mistake on some rounding job.(So it is wrong to put follow() in update())

And so I hope Adam could take a look at why collision solving gives wield output (504.00006/503.999999994). Why such figures so special?

And thanks again for help