Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Tweening between two directions.
- eastons
-
25 posts
Tweening between two directions.
In my current project ( http://scratch.mit.edu.ezproxyberklee.flo.org/projects/10728425 ) I have a enemy ship (NPC_Fighter) that has a current direction and the direction it wants to turn toward.
I would like to change the direction based on a variable IE ThisSpritesTurnSpeed. How would I create the inbetween frames?
Currently each loop the sprite looks up the direction to its target via a PointToXY function. Then it points in the direction of that value. It makes a very smooth animation but it turn much too fast. If you put some kind of timer it looks jittery. I guess Im looking for a Glide to Direction similar to Glide toXY that we already have.
Thanks,
Eastons
Edit: Oh if the projects main menu is confusing, just click on the hallway behind the robot.
I would like to change the direction based on a variable IE ThisSpritesTurnSpeed. How would I create the inbetween frames?
Currently each loop the sprite looks up the direction to its target via a PointToXY function. Then it points in the direction of that value. It makes a very smooth animation but it turn much too fast. If you put some kind of timer it looks jittery. I guess Im looking for a Glide to Direction similar to Glide toXY that we already have.
Thanks,
Eastons
Edit: Oh if the projects main menu is confusing, just click on the hallway behind the robot.
Last edited by eastons (June 14, 2013 03:12:45)
- drmcw
-
1000+ posts
Tweening between two directions.
Repeat until direction = direction you want
rotate by some amount
wait by some amount
The some amounts would need to be tweaked to make the animation the speed and smoothness you want.
rotate by some amount
wait by some amount
The some amounts would need to be tweaked to make the animation the speed and smoothness you want.
- eastons
-
25 posts
Tweening between two directions.
Any amount of wait causes slight jittering even if it is even .005. What I think I need to do is take the difference divide it by the turn speed then turn that amount.
- drmcw
-
1000+ posts
Tweening between two directions.
If you think a timer causes jitter then remove and to slow down make the rotation angle small. You can use angles less than one degree, so try turn by .1
- turkey3
-
1000+ posts
Tweening between two directions.
If you want the same frame rate of turning but different directions, you can try this. Say you want to turn 30° in 10 frames:
So to increase the speed you lower the frame rate but to increase smoothness you raise the frame rate (10). However, if you want to turn the variable “turn speed” until the direction is right do this. Say you want to turn to the direction 45°:
repeat (10)
turn right ((30) / (10))
repeat until <<((45) - ((turn speed) + (1))) < (direction)> and <(direction) < ((45) + ((turn speed) + (1)))>>
turn right (turn speed)
end
point in direction (45)
- eastons
-
25 posts
Tweening between two directions.
If you want the same frame rate of turning but different directions, you can try this. Say you want to turn 30° in 10 frames:So to increase the speed you lower the frame rate but to increase smoothness you raise the frame rate (10). However, if you want to turn the variable “turn speed” until the direction is right do this. Say you want to turn to the direction 45°:repeat (10)
turn right ((30) / (10))repeat until <<((45) - ((turn speed) + (1))) < (direction)> and <(direction) < ((45) + ((turn speed) + (1)))>>
turn right (turn speed)
end
point in direction (45)
Thanks! Ill check this out.
- Discussion Forums
- » Help with Scripts
-
» Tweening between two directions.