简体   繁体   中英

Nape space.step and constant impulse

I have a weird issue. If I move a body in nape every ENTER_FRAME (to get a constant movement) using a vector var vec:Vec2 = new Vec2(40,0); and apply it as impulse with body.applyImpulse(vec); , when I 'render' the scene doing space.step(1 / this._stage.frameRate);a at the same frame, and trace at that time the difference of movement in pixel of the body (compared to its position at the previous frame), it is not constant per frame. The result being sometimes the position is ahead like it rendered 2 impulses in the same frame while the next frame won't have any impulses or movement, and the sprite is shaky, which happens randomly. The space has no gravit (0,0);

How to get a nice constant movement for a body with impulse at every frame ? I tried to use body.position.setxy() but it defeats the purpose of the simulation...

I played a little bit with space.step(1 / this._stage.frameRate); and tried space.step(0.1 / this._stage.frameRate); The random shaking disappears but now the body shakes a tiny bit at everyframe. Any thoughts ?

EDIT Using now velocity instead of applyImpulse, still have the same issue

var old:Number = body.velocity.x;
body.velocity.x = dir.x*speed;
body.velocity.y = dir.y*speed;          
trace("DIFF", body.velocity.x-old);

I run this at everyframe and difference of position on x of the body is :

DIFF 0.19997499999993806
DIFF 0.19997499999993806
DIFF 0.19997499999993806
DIFF 0.19997499999993806
DIFF 0.19997499999993806
DIFF 0.19997499999993806
DIFF 0.19997499999993806
DIFF 0.29992500624990726
DIFF 0.0999999999999659
DIFF 0.19997499999993806
DIFF 0.19997499999993806

So every once in a while, the result of the velocity applied to the object is not constant, as it renders "ahead" once in a while and "corrects" itself if I may say.

Ok found the issue, posting if someone else faces the same issue :

space.step(1 / this._stage.frameRate, 1, 1)

corrects the issue since I have no grativy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM