S
shadow7692
Guest
Hello, this is my first post after weeks of using the forums as an excellent resource. I come from a Python background and there are built-in functions such as
I have written a script (shown below), which currently causes my NPC to frantically jitter around, and from my understanding, this is because the whole section is being run every frame. I want to change it so that
I think I need to use alarms (which I don't fully understand yet), but I'm not too sure. I appreciate any guidance.
EDIT: I ended up using @kburkhart84 's suggestion of variables instead of alarms. [SOLVED]
wait()
, which allow me to 'pause' the execution of the script.I have written a script (shown below), which currently causes my NPC to frantically jitter around, and from my understanding, this is because the whole section is being run every frame. I want to change it so that
HorizontalMovement = choose(-1, 0, 1);
and VerticalMovement = choose(-1, 0, 1);
is only run every, say, 60 frames. All while the rest of the script runs normally.I think I need to use alarms (which I don't fully understand yet), but I'm not too sure. I appreciate any guidance.
EDIT: I ended up using @kburkhart84 's suggestion of variables instead of alarms. [SOLVED]
Code:
HorizontalMovement = choose(-1, 0, 1);
VerticalMovement = choose(-1, 0, 1);
var TargetX = x + HorizontalMovement * Walkspeed;
var TargetY = y + VerticalMovement * Walkspeed;
x = TargetX
y = TargetY
if (HorizontalMovement == 0 and VerticalMovement == 0) {
State = CharacterState.Idle;
Y = 0;
AnimationLength = 4;
};
else {
State = CharacterState.Walk;
Y = 1;
AnimationLength = 6;
};
Last edited by a moderator: