Collision for motion_set movement

Y

YuutaroHiroshio

Guest
So I'm attempting to create virtual controls for a top-down shooter base engine that I'm working on based on a tutorial series I found, using a virtual "joypad" on my Android tablet screen to control the angle of the player's movement. I am avoiding from using solids as per the advice of several sources/tutorials, but the collision code I'm trying to use either brings the character to a permanent stop and unable to move, or just ignores the walls entirely.
I don't know if there's an easier method of controlling collisions for movements based off of the motion_set coding, as the collision is based on keyboard checks, so does anyone have better collision code for what I'm trying to do?

Here's the code I'm currently using for collision handling, an attempted adaptation of it at least: http://pastebin.com/DvYXHwhz

Thanks in advance.
 
A

Aura

Guest
Using custom variables for collisions won't help, since motion_set() relies on speed and direction. An easier way would be to use this:

Code:
var nx, ny;
nx = lengthdir_x(speed, direction);
ny = lengthdir_y(speed, direction);
if (place_meeting(x + nx, y + ny, obj_wall)) {
   while (!place_meeting(x + sign(nx), y + sign(ny), obj_wall)) {
      x += sign(nx);
      y += sign(ny);
   }
   speed = 0;
}
The code above should work without changes if you're using four directional movement.
 
Y

YuutaroHiroshio

Guest
I tried that code, however, I still seem to get the same issues when I apply that code. Not sure whether it's something I'm doing wrong specifically or not. I should mention the fact that the controls use more than four-directional movement, since the direction is based off of the mouse X and Y in relation to where you press on the circle used for movement.
 
A

Aura

Guest
Post the code that you're using for movement, so that we can suggest alternatives. The code I posted might not work under certain circumstances.
 
Y

YuutaroHiroshio

Guest
These are the event scripts used in the ui touch controls:

Step event

if(!mouse_check_button(mb_left))
{
if (obj_player.movespeed > 0)
{
obj_player.movespeed -= 1;
}
else obj_player.movespeed = 0;
}

Left Mouse Button event
obj_player.movedir = point_direction(x, y, mouse_x, mouse_y);
obj_player.movespeed = obj_player.maxmovespeed;
with(obj_player)
{
script_execute(scr_player_collision); <- refers back to the script I linked in the OP
}

EDIT: So I think I can identify where the problem is happening but not sure how to go about fixing it. With the current collision code, because the player moves based on the variable movespeed (where the speed is set once I start clicking on the virtual circlepad), the moment I collide with something, the collision overrides the movement entirely and locks out movement whilst the character is against the wall object. If there is a way to do place_meeting based on the direction the character is currently moving towards, that could work better. If that helps with working out a solution, let me know.
 
Last edited by a moderator:
Top