Gasil
Member
Hello, would you help me with this please? With top view, the character has tank movement, so it rotates with left and right to change directions and goes forward with up, etc. With a script, I'm trying to make it rotate to a given target to face it upon examination, but with the way I have set up things, the character will always rotate counterclockwise, so sometimes it looks silly taking the longest turn to face the target.
On step event I have this:
This will keep dir from positive 359 to 0. I did this to prevent dir to increase or decrease indefinitely if character rotates too much to a single direction, I thought it could make things more easier to code in direction related stuff, but I'm not sure if it's necessary.
This is as much as I could write in the script. If player dir is 15, and target dir is 350, naturally I'd want the character to decrease dir to 0 and further so it wraps around with the step event code and reach 350, cause it's the closest route, but currently it will go all the way from 15 to 350. I'm not sure how to accomplish that dinamically or what values to compare to give it a negative turnSpd when necessary.
Thanks.
On step event I have this:
GML:
if(dir >= 360)
dir -= 360;
else if(dir < 0)
dir += 360;
GML:
var trgtDir, turnSpd;
trgtDir = argument0;
turnSpd = argument1;
with(obj_player)
{
//Turn player object.
dir = lerp(dir, trgtDir, turnSpd);
}
Thanks.