D
Darren
Guest
How do I figure collision when I move my object based on mouse movement? I'm not physically rotating the mask, I'm using draw sprite trickery, but the movement going in a direction according to the mouse is screwing up any collision code I attempt. Basically I need my character to always move toward the cursor, which it does, but I can't figure out walls.
This is my code with no collision
dir = point_direction(x, y, mouse_x, mouse_y);
if distance_to_point(mouse_x, mouse_y) > 1{
{
if UpKey
{
x+=lengthdir_x(vspd,dir);
y+=lengthdir_y(vspd,dir);
}
if LeftKey
{
x += lengthdir_x(hspd ,dir+90);
y += lengthdir_y(hspd ,dir+90);
}
if RightKey
{
x-=lengthdir_x(hspd ,dir+90);
y-=lengthdir_y(hspd ,dir+90);
}
}}
if DownKey
{
x-=lengthdir_x(vspd,dir);
y-=lengthdir_y(vspd,dir);
}
I can't add collision how I would a normal top down game where you are always "W" for up, because sometimes "W" becomes down, left or right depending on where the mouse is. How would I go about sorting this?
This is my code with no collision
dir = point_direction(x, y, mouse_x, mouse_y);
if distance_to_point(mouse_x, mouse_y) > 1{
{
if UpKey
{
x+=lengthdir_x(vspd,dir);
y+=lengthdir_y(vspd,dir);
}
if LeftKey
{
x += lengthdir_x(hspd ,dir+90);
y += lengthdir_y(hspd ,dir+90);
}
if RightKey
{
x-=lengthdir_x(hspd ,dir+90);
y-=lengthdir_y(hspd ,dir+90);
}
}}
if DownKey
{
x-=lengthdir_x(vspd,dir);
y-=lengthdir_y(vspd,dir);
}
I can't add collision how I would a normal top down game where you are always "W" for up, because sometimes "W" becomes down, left or right depending on where the mouse is. How would I go about sorting this?
Last edited by a moderator: