之前有稍微了解到,像是4.2物理革命裡展示的那位盪鞦韆女孩,使用到了外部的js物理引擎
我想知道,在web裡要實現物理模擬的話,該怎麼做?推薦使用哪種物理引擎?實現的基本的思路是?
請給我一個方向,我會去研究的,非常感謝!!
之前有稍微了解到,像是4.2物理革命裡展示的那位盪鞦韆女孩,使用到了外部的js物理引擎
我想知道,在web裡要實現物理模擬的話,該怎麼做?推薦使用哪種物理引擎?實現的基本的思路是?
請給我一個方向,我會去研究的,非常感謝!!
Spine implements and plays physics transparently. In the simplest case, you just play the animation without considering physics. However, if you are using a game library such as PixiJS or Phaser where a Spine skeleton is usually contained within a game object, you must understand that movements and rotations applied to the game object don't directly affect the physics state of the skeleton.
To be more precise:
gameObject.x
, physics constraints aren't affected.gameObject.skeleton.x
, physics constraints will take effect.However, in your game engine, you typically want to move the game object, not the skeleton.
To make the physics constraints affect the skeleton without actually moving the skeleton, there are two main APIs:
skeleton.physicsTranslate(x: number, y: number)
for translationsskeleton.physicsRotate(x: number, y: number, degrees: number)
for rotationsThere is an additional consideration to keep in mind: you need to transform the distance from the game engine space to the skeleton space. Usually, we have utility functions in our runtime to handle this transformations. For example, in Phaser, we have:
skeletonToPhaserWorldCoordinates(point: { x: number; y: number })
phaserWorldCoordinatesToSkeleton(point: { x: number; y: number })
You can refer to the following examples that use the APIs mentioned above:
skeleton.physicsTranslate
usage.