Detecting Model movement against a wall

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Detecting Model movement against a wall

Post by rrTea »

I have a "Player" model whose Velocity.X and Velocity.Y change depending on input. This model also has a Collision defined against "Wall" model as "Stop". So as expected, when the Player collides with a Wall, it stops. So far so good.

The problem I bumped into is that I can't find a way to detect whether the player is changing its position when it is running against a wall (standing left from the wall and pushing right kind of situation). For example I tried this among other things:

Code: Select all

if (
PlayerPrevPos.X != CurrentModel.Position.X ||
PlayerPrevPos.Y != CurrentModel.Position.Y)
check.Text = "1"; //moving
else check.Text = "0";

PlayerPrevPos.X = CurrentModel.Position.X;
PlayerPrevPos.Y = CurrentModel.Position.Y;
This works perfectly when the player is either idle or moving freely, but when pushed against a wall it constantly returns "1"! How is that possible - the coordinates are surely the same?

I tried checking for movements in various other ways, but I'm constantly getting the same results (movement is registered correctly except when the player is pressing against a wall) so there must be some simple concept I'm unaware of...

Edit 01: So I solved this by moving the code from the model's State to main OnUpdate and now it works. I assumed it wasn't working because I was using Velocity to move the model around, so at that particular moment when I was checking it the model was still embedded in the "wall" model before ZGE pulled it out of it (so the movement was registered before it was "corrected")... or something like that? Hmm I'd really like to avoid keeping these checks in main (or in a State's) OnUpdate...

Edit 02: Just did some tests and it seems my theory for why this happens is wrong... but regardless, right now it works so I'll leave it like that.
Post Reply