T
TaPeace
Guest
Hi there, i trying to prototype with some collision stuff and need some help to unterstand it...
The Code works fine if i hit the objects just horizontal or vertical. But if i hit a slope diagonal, then i get stuck sometimes. The same when i hit a corner from a rectangle.
Any advice?
Thanks
Code in Player Step Event
The Code works fine if i hit the objects just horizontal or vertical. But if i hit a slope diagonal, then i get stuck sometimes. The same when i hit a corner from a rectangle.
Any advice?
Thanks
Code in Player Step Event
Code:
//Get Inputs
kUp = keyboard_check(ord("W"));
kDown = keyboard_check(ord("S"));
kLeft = keyboard_check(ord("A"));
kRight = keyboard_check(ord("D"));
kRestart = keyboard_check(ord("R"));
kEscape = keyboard_check(vk_escape);
//Movement
if kUp {vspeed -= MySpeed};
if kDown {vspeed += MySpeed};
if kLeft {hspeed -= MySpeed};
if kRight {hspeed += MySpeed};
//Decceleration
if speed > 0 {
speed -= Decceleration;
} else {
speed = 0;
}
//Limit Speed
if speed >= MaxSpeed {
speed = MaxSpeed;
}
//Horizontal Collisioncheck
if place_meeting(x + hspeed,y,oSolids) {
while !place_meeting(x + sign(hspeed),y,oSolids) {
x += sign(hspeed);
}
hspeed = 0;
}
//Vertical Collisioncheck
if place_meeting(x,y + vspeed,oSolids) {
while !place_meeting(x,y + sign(vspeed),oSolids) {
y += sign(vspeed);
}
vspeed = 0;
}
//Wrap Screen
move_wrap(1,1,0);
//Restart
if kRestart {game_restart()};
//Exit Game
if kEscape {game_end()};
Attachments
-
15 KB Views: 7