M
mentalredux
Guest
Hello there. I currently have a bit of code that controls the playable character's speed and I like how it works. If the cursor is far away the object speeds up and gradually slows down as it reaches the cursor to simulate a running speed and walking speed. It is in a step event but I would like to assign it to a variable that takes it's place when the steps are being checked and move it to over the the create event area.
I am having difficulty with this code and collision checking. Is there a way that I can apply the above code to a variable that I can use instead of speed so I can use the code below for collision control?
Thank you.
GML:
if distance_to_point (mouse_x,mouse_y)>200{speed=10};
else
if distance_to_point (mouse_x,mouse_y)>170{speed=8};
else
if distance_to_point (mouse_x,mouse_y)>150{speed=7};
else
if distance_to_point (mouse_x,mouse_y)>50{speed=4};
else
if distance_to_point (mouse_x,mouse_y)>25{speed=3};
else
if distance_to_point (mouse_x,mouse_y)>5{speed=2};
else
if distance_to_point (mouse_x,mouse_y)>3{speed=1};
else
if distance_to_point (mouse_x,mouse_y)<1{speed=0};
GML:
//H
if(place_meeting(x + speed, y, objWall))
{
while(!place_meeting(x + sign(speed), y, objWall))
{
x += sign(speed);
}
speed = 0;
}
x += speed;
//V
if(place_meeting(x, y + speed, objWall))
{
while(!place_meeting(x, y + sign(speed), objWall))
{
y += sign(speed);
}
speed = 0;
}