A
AwesomeAlvin
Guest
So right now, this is my player's movement and collision code for a top down shooter:
It's pretty much Shaun Spalding's one. However, how do I implement this for my enemies? How would I be able to capture their horizontal and vertical speed. Would I just have to use hspeed or vspeed, or is there a way to use the custom speed variables for this?
If I were to change the variables from the customs and use the built it, it would look like this for the enemies:
But I find it weird that my player is using vsp and hsp while enemies are using vspeed and hspeed. Should that be fine though?
And also, I want my enemies to be able to collide with each other; how can I do this by using place_meeting?
Any help would be appreciated, thanks!
Let me know if there's any more information I can provide.
Code:
hsp = walkSpeed * (keyboard_check(ord('D')) - keyboard_check(ord('A')));
vsp = walkSpeed * (keyboard_check(ord('S')) - keyboard_check(ord('W')));
if (place_meeting(x+hsp,y, obj_wall)) {
while (!place_meeting(x+sign(hsp),y,obj_wall)) {
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
if (place_meeting(x,y+vsp, obj_wall)) {
while (!place_meeting(x,y+sign(vsp),obj_wall)) {
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
If I were to change the variables from the customs and use the built it, it would look like this for the enemies:
Code:
if (place_meeting(x+hspeed,y, obj_wall)) {
while (!place_meeting(x+sign(hspeed),y,obj_wall)) {
x += sign(hspeed);
}
hspeed = 0;
}
if (place_meeting(x,y+vspeed, obj_wall)) {
while (!place_meeting(x,y+sign(vspeed),obj_wall)) {
y += sign(vspeed);
}
vspeed = 0;
}
And also, I want my enemies to be able to collide with each other; how can I do this by using place_meeting?
Any help would be appreciated, thanks!
Let me know if there's any more information I can provide.