Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The set linear velocity doesnt affect a sprite when written inside an event handler.. but if i call setlinear velocity inside the main if the setlinearvelocity is called at the beginning of game code moves..but not when i call it within a event handler..either keypress or mouse,it doesnt work?

Please ..any help would be greatly appreciated

share|improve this question
Did you make sure that the event handler gets called? Maybe post the code snippet in question? – bummzack Aug 12 '10 at 6:26
up vote 1 down vote accepted

Could it be that the event handler gets called at the wrong time in Box2D's pipeline? Or are you not unintentionally overwriting it somewhere else (like in an update loop)? Could you set a variable to the desired velocity in the event handler and set that velocity in an update that gets called more regularly?
Pure speculation - I never used flash's event system the way it's supposed to be used (I prefer update loops) and I never used Box2D so take it for what it's worth.

share|improve this answer
thankyou for replyin..i got it worked.i made the allowsleep to false..and it worked :) well can i ask u another question...i am making a pool game and now when i add the linear velocity it moves in the correct angle but it now sticks towards the point of collision with the wall. i suspect it is because there is some thing wrong with the values provided to setlinearvelocity... :) thankyou for replyin by the way :) – Vishnu Aug 12 '10 at 7:34
@Vishnu: Sounds like you are setting the velocity every step, rather than once – Bart van Heukelom Aug 12 '10 at 10:28
Bart has a good point. In a pool game you should only apply the force once. Either that or it's stuck with the wall. There are two things I tend to do (if I manage velocities myself on a per frame basis). Convert the velocity to a 'desired velocity'->calculate the difference betweem the desired velocity and the actual velocity and convert that to a force, Secondly, again if managing velocity myself, upon collision move the object out of the face ever so slightly, to prevent getting stuck. In general though - apply force and let the physics engine handle resulting velocities and collisions. – Kaj Aug 12 '10 at 15:22
I think that would boil down to: Use the force wisely, young Padawan. (Sorry, couldn't resist) – bummzack Aug 13 '10 at 6:24
well..i figured it out..thankyou..the problem was i dint call WakeUp function with the setlinear velocity – Vishnu Aug 14 '10 at 5:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.