Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualskuhtz

Posted 09 December 2012 - 04:04 AM

This is a bit of code obtained from Nick Gravelyn's RPG tutorial which will bounce the player character away from an nc character it collides with, you could possibly make something useful out of it. Sprite is the PC that is moving into s which is the npc, the Origin is the Position + an offset which is where you determine collision points.

if (AnimatedSprite.AreColliding(sprite, s))
{
// we are assuming that npcs will never move
Vector2 d = Vector2.Normalize(s.Origin - sprite.Origin);
sprite.Position =
s.Position - (d * (sprite.CollisionRadius + s.CollisionRadius));
}


I modified the code using ideas out of this, but I still can't get it working properly. This is the only thing I've had major problems with and it's so aggravating Posted Image

Although this doesn't work maybe some tips can be salvaged out of this?
Vector2 direction = Vector2.Normalize(collisionPoint - player1Origin);
player1Pos = collisionPoint - (direction * player1Speed);

#1skuhtz

Posted 09 December 2012 - 04:04 AM

This is a bit of code obtained from Nick Gravelyn's RPG tutorial which will bounce the player character away from an nc character it collides with, you could possibly make something useful out of it. Sprite is the PC that is moving into s which is the npc, the Origin is the Position + an offset which is where you determine collision points.

if (AnimatedSprite.AreColliding(sprite, s))
{
// we are assuming that npcs will never move
Vector2 d = Vector2.Normalize(s.Origin - sprite.Origin);
sprite.Position =
s.Position - (d * (sprite.CollisionRadius + s.CollisionRadius));
}


I modified the code using ideas out of this, but I still can't get it working properly. This is the only thing I've had major problems with and it's so aggravating Posted Image

Although this doesn't work maybe some tips can be salvaged out of this?
				    Vector2 direction = Vector2.Normalize(collisionPoint - player1Origin);
				    player1Pos = collisionPoint - (direction * player1Speed);

PARTNERS