Original Post
Hey guys,
im having a problem with my collition result. there are blocks on my map which i want set as unwalkible. I have managed to do this by putting a rectangle around the block and the character then using intesect to determine collition. the test works but thats not the problem.
As when the collition does happen im unsure what to do as so far I have put the colltion in the directional keys so I know which way the charater is facing when the colltion happens. I set the posion opposite to the direction of the charecter when ther colliton occurs.
Problem is when the charater collides sometimes he doesn't get pushed back straight away so he still is colliding. and when I press another directional key that part of the code runs. for if he was stuck on the colltion moving from right to left then I pressed the up key that part of the code tells him to move down even know he is facing the east side of the block =/.
Ive tried hours to get this working and finding it really hard to fix any help would be appresiated my code for the directional keys is below. ps. using classes etc is behond me and not important for my project before you say it looks messy >< lol..
Basically the code is the same for each directional key doing the opposite on collition. its when the character doesn't get moved or gets stuck in the colltion and another key gets pressed is when I have the problem.
I really really apreshiate any help as tried so long to get this working and can't
im having a problem with my collition result. there are blocks on my map which i want set as unwalkible. I have managed to do this by putting a rectangle around the block and the character then using intesect to determine collition. the test works but thats not the problem.
As when the collition does happen im unsure what to do as so far I have put the colltion in the directional keys so I know which way the charater is facing when the colltion happens. I set the posion opposite to the direction of the charecter when ther colliton occurs.
Problem is when the charater collides sometimes he doesn't get pushed back straight away so he still is colliding. and when I press another directional key that part of the code runs. for if he was stuck on the colltion moving from right to left then I pressed the up key that part of the code tells him to move down even know he is facing the east side of the block =/.
Ive tried hours to get this working and finding it really hard to fix any help would be appresiated my code for the directional keys is below. ps. using classes etc is behond me and not important for my project before you say it looks messy >< lol..
if (keyboardState.IsKeyDown(Keys.Left) || (gamepad1State.ThumbSticks.Left.X < 0f))
{
if (charBounds.Intersects(mBlock1))
{
skullPosition.X++;
}
else if (!charBounds.Intersects(mBlock1))
{
if (skullTimeSinceLastFrame > skullMilliSecondsPerFrame)
{
skullTimeSinceLastFrame -= skullMilliSecondsPerFrame;
++skullCurrentFrame.X;
if (skullCurrentFrame.X >= 3)
{
skullCurrentFrame.X = 0;
skullCurrentFrame.Y = 1;
}
}
skullPosition.X -= skullSpeed;
}
}
else if (keyboardState.IsKeyDown(Keys.Right) || (gamepad1State.ThumbSticks.Left.X > 0f))
{
if (charBounds.Intersects(mBlock1))
{
skullPosition.X--;
}
else
{
if (skullTimeSinceLastFrame > skullMilliSecondsPerFrame)
{
skullTimeSinceLastFrame -= skullMilliSecondsPerFrame;
++skullCurrentFrame.X;
if (skullCurrentFrame.X >= 3)
{
skullCurrentFrame.X = 0;
skullCurrentFrame.Y = 2;
}
}
skullPosition.X += skullSpeed;
}
}
else if (keyboardState.IsKeyDown(Keys.Up) || (gamepad1State.ThumbSticks.Left.Y > 0f))
{
if (charBounds.Intersects(mBlock1))
{
skullPosition.Y++;
}
else
{
if (skullTimeSinceLastFrame > skullMilliSecondsPerFrame)
{
skullTimeSinceLastFrame -= skullMilliSecondsPerFrame;
++skullCurrentFrame.X;
if (skullCurrentFrame.X >= 3)
{
skullCurrentFrame.X = 0;
skullCurrentFrame.Y = 3;
}
}
skullPosition.Y -= skullSpeed;
}
}
else if (keyboardState.IsKeyDown(Keys.Down) || (gamepad1State.ThumbSticks.Left.Y < 0f))
{
if (charBounds.Intersects(mBlock1))
{
skullPosition.Y--;
}
else
{
if (skullTimeSinceLastFrame > skullMilliSecondsPerFrame)
{
skullTimeSinceLastFrame -= skullMilliSecondsPerFrame;
++skullCurrentFrame.X;
if (skullCurrentFrame.X >= 3)
{
skullCurrentFrame.X = 0;
skullCurrentFrame.Y = 0;
}
}
skullPosition.Y += skullSpeed;
}
}
Basically the code is the same for each directional key doing the opposite on collition. its when the character doesn't get moved or gets stuck in the colltion and another key gets pressed is when I have the problem.
I really really apreshiate any help as tried so long to get this working and can't