lo-th / Oimo.js

Lightweight 3d physics engine for javascript
http://lo-th.github.io/Oimo.js
MIT License
3.05k stars 301 forks source link

How to apply force to a body? #56

Open x1911 opened 7 years ago

x1911 commented 7 years ago

for example, i want a ball move to right side,

and i have tried to use body.applyImpulse ({ x:0, y:0, z:100 }, 10);

unfortunately it dosen't work.

BTW: how to make a ball jump in this case?

w84miracle commented 7 years ago

Forces are directional, hence your force should be a vector3 too.

https://github.com/lo-th/Oimo.js/blob/159ef4e24c79786e779826d6f9273378be2211c8/src/core/RigidBody.js#L425

x1911 commented 7 years ago

@w84miracle thanks for reply, have you some example to show how this works?

x1911 commented 7 years ago

has other way to apply force except body.applyImpulse ? if i want to keep the gravity [0, 9.8 ,0]

lo-th commented 7 years ago

no look code in http://lo-th.github.io/Oimo.js/#planet you can keep gravity ;)

lo-th commented 7 years ago

maybe your impulse is no strong enouth to jump i try a example soon

icedcoke commented 4 years ago

force in oimo needs to be updated in every frame. no update will not see the effect. body.applyImpulse ({x:0, y:0, z:0}, {x:0, y:20, z:0});