Adding Custom Animations Using a Tween Class

Create a 3D RPG Game with THREE.js Interacting with the Environment
3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€60.03
List Price:  €85.76
You save:  €25.73
£52.33
List Price:  £74.76
You save:  £22.43
CA$98.16
List Price:  CA$140.24
You save:  CA$42.07
A$107.66
List Price:  A$153.80
You save:  A$46.14
S$90.65
List Price:  S$129.50
You save:  S$38.85
HK$543.95
List Price:  HK$777.10
You save:  HK$233.15
CHF 55.74
List Price:  CHF 79.64
You save:  CHF 23.89
NOK kr704.22
List Price:  NOK kr1,006.07
You save:  NOK kr301.85
DKK kr448.55
List Price:  DKK kr640.81
You save:  DKK kr192.26
NZ$122.29
List Price:  NZ$174.71
You save:  NZ$52.42
د.إ257.03
List Price:  د.إ367.21
You save:  د.إ110.17
৳8,550.49
List Price:  ৳12,215.51
You save:  ৳3,665.02
₹6,160.91
List Price:  ₹8,801.68
You save:  ₹2,640.76
RM295.77
List Price:  RM422.55
You save:  RM126.77
₦102,986.63
List Price:  ₦147,130.07
You save:  ₦44,143.43
₨19,873.60
List Price:  ₨28,392.08
You save:  ₨8,518.47
฿2,297.12
List Price:  ฿3,281.75
You save:  ฿984.62
₺2,931.18
List Price:  ₺4,187.58
You save:  ₺1,256.39
B$378.54
List Price:  B$540.79
You save:  B$162.25
R1,215.60
List Price:  R1,736.64
You save:  R521.04
Лв117.47
List Price:  Лв167.82
You save:  Лв50.35
₩99,507.58
List Price:  ₩142,159.78
You save:  ₩42,652.20
₪231.65
List Price:  ₪330.95
You save:  ₪99.29
₱4,067.88
List Price:  ₱5,811.51
You save:  ₱1,743.62
¥10,540.84
List Price:  ¥15,058.99
You save:  ¥4,518.15
MX$1,286.09
List Price:  MX$1,837.35
You save:  MX$551.26
QR255.89
List Price:  QR365.57
You save:  QR109.68
P940.74
List Price:  P1,343.98
You save:  P403.23
KSh9,066.95
List Price:  KSh12,953.35
You save:  KSh3,886.39
E£3,325.37
List Price:  E£4,750.73
You save:  E£1,425.36
ብር10,434.29
List Price:  ብር14,906.77
You save:  ብር4,472.48
Kz64,180.83
List Price:  Kz91,690.83
You save:  Kz27,510
CLP$67,270.75
List Price:  CLP$96,105.19
You save:  CLP$28,834.44
CN¥498.82
List Price:  CN¥712.63
You save:  CN¥213.81
RD$4,439.79
List Price:  RD$6,342.83
You save:  RD$1,903.04
DA9,071.96
List Price:  DA12,960.50
You save:  DA3,888.54
FJ$159.14
List Price:  FJ$227.36
You save:  FJ$68.21
Q537.72
List Price:  Q768.21
You save:  Q230.48
GY$14,685.01
List Price:  GY$20,979.49
You save:  GY$6,294.47
ISK kr8,527.67
List Price:  ISK kr12,182.91
You save:  ISK kr3,655.24
DH641.97
List Price:  DH917.14
You save:  DH275.17
L1,172.36
List Price:  L1,674.88
You save:  L502.51
ден3,700.23
List Price:  ден5,286.27
You save:  ден1,586.03
MOP$561.62
List Price:  MOP$802.35
You save:  MOP$240.73
N$1,224.19
List Price:  N$1,748.92
You save:  N$524.73
C$2,583.52
List Price:  C$3,690.90
You save:  C$1,107.38
रु9,887
List Price:  रु14,124.89
You save:  रु4,237.89
S/237.70
List Price:  S/339.59
You save:  S/101.88
K299.40
List Price:  K427.74
You save:  K128.33
SAR262.46
List Price:  SAR374.97
You save:  SAR112.50
ZK1,591.85
List Price:  ZK2,274.17
You save:  ZK682.32
L305.52
List Price:  L436.47
You save:  L130.95
Kč1,458.71
List Price:  Kč2,083.96
You save:  Kč625.25
Ft23,478.12
List Price:  Ft33,541.62
You save:  Ft10,063.49
SEK kr661.65
List Price:  SEK kr945.26
You save:  SEK kr283.60
ARS$98,669.88
List Price:  ARS$140,963.01
You save:  ARS$42,293.13
Bs485.11
List Price:  Bs693.05
You save:  Bs207.93
COP$269,930.97
List Price:  COP$385,632.20
You save:  COP$115,701.23
₡35,239.73
List Price:  ₡50,344.64
You save:  ₡15,104.90
L1,843.77
List Price:  L2,634.08
You save:  L790.30
₲498,216.21
List Price:  ₲711,767.95
You save:  ₲213,551.74
$U2,810.52
List Price:  $U4,015.21
You save:  $U1,204.68
zł254.83
List Price:  zł364.05
You save:  zł109.22
Already have an account? Log In

Transcript

Referring back to context action in version four of the game. Notice how we're adding tweens, tweens, an array of potential tweens in the game, a tween takes a variety of parameters. The first one is the target. So it's going to be in this instance, the target is left position. So the left door position. The second parameter is the channel.

So it's left position, Zed, then it takes the end value. So it's going to be the current left positions at minus 240. So it's going to move nearly two and a half meters left. Then the duration in seconds, so it's going to be two seconds. And then what happens once it comes to the end of the tween. In this instance, there's a function defined that removes this particular tween.

From our tweens array, there is a option for an additional parameter, which is the easy method. And if you look through the various easing methods, you'll see that there are a variety of them in our means it's going to go start slow and ramp up, and then at the end is going to decelerate to a stop. And it's used good you're going to use a quadratic function to do that. The second tween which is moving the ride door has a more complicated end function on complete function. It still has to remove itself from the tweens array, but it also deletes the camera target that means that the camera comes back to the default camera and stops showing the cutscene camera. It finds the particular door that we're dealing with.

And on that basis finds the left and right doors and the Left, left and right proxies and it sets the proxy position to the position of the left and right doors. So the ray caster is no longer blocked. Because the proxies are now and meshed inside the door. You may have noticed already there in the animate function. There is a method based on the tweens. So for each tween, we call update passing in the Delta time that's elapsed.

So that's all you really need to know about tweens. They take a target a channel and then position, a duration and an on complete function. But if you want to look at the source for them easing is is in the in the game JavaScript file. And you can see all the different options you've got for easy bounces, etc. And there's your tween class very simple. Just takes these parameters and assigns them and then has a simple update function, which uses the easing class to decide on on its position based on the current time.

Very useful tweens to animate properties over time with some nice easy

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.