Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by robw00t

Hello, I'm working on a top-down game where a fixed entity should prevent a passive entity (the player) from moving through it.

I place the fixed entity in the game world and move the passive entity towards it by updating the passive entity's (player) pos.* values in the update() method:

this.pos.x = this.pos.x + xd; (where xd is x delta)
this.pos.y = this.pos.y + yd;

I know some accel / velocity features exist already but they don't create the movement I want so I'm updating the x and y coordinates manually.

The collision works perfectly when I collide the player with the fixed entity from a vertical approach: the player stops when it hits the entity as expected.

When I approach from a horizontal direction, however, the player 'jumps' to above or below the fixed entity instead of stopping.

If the fixed entity's top most pixel is at y coordinate 10 and the player's bottom most pixel is at y coordinate 15 when the player collides with the fixed entity heading east the player's bottom y coordinate is jumped up to 10 from 15 and the player continues to move east ABOVE the fixed entity instead of stopping.

If I reverse the if statements on lines 288 and 304 of entity.js so the horizontal collision is checked before the vertical one then the problem is reversed; my horizontal collisions work perfectly and the vertical ones cause the player to jump around the fixed entity.

Is this a known bug with the collision engine on top-down games? I'd be happy to provide some source code and/or a video demonstrating the situation.

-Rob

1 decade ago by monkeyArms

Hi Rob,

Could you share the code in your player entity that seems to be conflicting with the engine core? I'm also curious why your manually coding the player entity movements - for what goal?

1 decade ago by dominic

Setting an Entity's position manually will (by definition) overrule the collision detection.

What type of movement are you trying to implement? For continuous movement (i.e. not instantaneous "teleporting") you should always be able to use the .vel properties.

1 decade ago by robw00t

The movement I'm trying to accomplish is a linear interpolation from the player entity to the mouse cursor. Maybe I can accomplish this with the .vel property and all is good? I'll try messing around with that some more.

Here's a vid (with a poor framerate) showing the collision bug and the movement to some degree despite the bad framerate.

You can see that as the cursor gets closer to the player entity the player moves slower.

https://dl-web.dropbox.com/get/tmp/collision.mov?w=303b8743

This is the movement code I'm using in the player entity's update method:

this.data.x = mouse.x;
this.data.y = mouse.y;

var xd = this.lerp(0.035,this.pos.x,this.data.x) - this.pos.x;
var yd = this.lerp(0.035,this.pos.y,this.data.y) - this.pos.y;

this.pos.x = this.pos.x + xd;
this.pos.y = this.pos.y + yd;

1 decade ago by robw00t

quick update: it looks like using .vel does resolve the collision issue. Though, the movement behavior by updating the .vel property isn't quite the same as what I had before... I'll mess with it and see if I can get it where I want it.

One more question: occasionally I'll need to teleport the player from one location to another. Is the best practice in that instance to update the .pos property?

Thanks,

-Rob
Page 1 of 1
« first « previous next › last »