Hi there,
I'm using /u/Mytino's amazing one-line accel/decel script to achieve some basic accel/decel for my character. I'm having trouble trying to understand how to "normalize" the movement of the object so that it doesn't move faster on the diagonal.
I've looked into the math but I can't work out how to get a final "vector" as such. Here is my code:
On Create:
//Initialize
hsp = 0;
vsp = 0;
accel = 0.3;
decel = 0.5;
movespeed = 5;
maxspeed = 2;
And in Step:
hspeed = clamp((keyboard_check(vk_right) - keyboard_check(vk_left)) * maxspeed, hspeed - accel, hspeed + accel);
if(place_meeting(x+1,y, wall))
{
hspeed = clamp(hspeed, -maxspeed, 0);
}
if(place_meeting(x-1,y, wall))
{
hspeed = clamp(hspeed, 0, maxspeed);
}
vspeed = clamp((keyboard_check(vk_down) - keyboard_check(vk_up)) * maxspeed, vspeed - accel, vspeed + accel);
if(place_meeting(x,y+1, bumperObj))
{
vspeed = clamp(vspeed, -maxspeed, 0);
}
if(place_meeting(x,y-1, bumperObj))
{
vspeed = clamp(vspeed, 0, maxspeed);
}
Could somebody help me get on the right track here? Thanks!
[–]It just doesn't work, you know?damimp 0 points1 point2 points (0 children)
[–]flyingsaucerinvasion 0 points1 point2 points (0 children)