LoginSignup
0
0

More than 5 years have passed since last update.

【PlayCanvas】1秒間にnドット移動したい

Posted at

1.初期化時

// speedというVec2型の変数を用意する。
this.speed = new pc.Vec2();
this.speed.set(10, 10);

// 移動量を計算する変数を用意する。
var tmp = new pc.Vec2();

2.update時

// tmp変数に移動量を代入する。
this.tmp.set(this.speed.x, this.speed.y);

// Vec2のscaleメソッドにupdate変数の引数であるdtを引き渡す。
// dtは1フレームにかかった時間を示す。
// scaleメソッドにdtを指定することで1フレームで移動する値を算出する。
this.tmp.scale(dt);

// tmp変数に1フレームでの移動量が格納されているので、移動対象のpositionに加算する。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0