Using keyboard to apply force to a wheel

Hi everyone,

I will make this short and sweet as my laptop keyboard has just died on me and its randomly pasting things (and driving me insane).

I created a circle shape and attached it to a body.

Using keyboard input, i opted for a basic way to move my wheel...

private var vx:Number = 0;

//if right key is down
wheel.wakeUp();
vx += 1;
wheel.m_angularVelocity = vx;

It works but not the way i want to and after spending 5 hours trying to come to terms with how to achieve it (searched all forums) i cannot get it to work the way i want... i need some help to get me started.

Can someone advise me on what i should be working with in regards to basic 2d car movement.. you know, if i press and hold right then the wheel will accelerate to a top speed... when the key is released, the wheel will decelrate to a stop.

Box2D is massively complex for me and i have been putting the hours in but i cant figure this out, my way has intense lag when it comes to moving. I know that ApplyTorque exists but the wheel just seems to wheelspin. If you could offer me your advice on how to move a wheel correctly i would be forever greatful.

Can someone tell me if there is an API similar to APE? I found an API somewhere online but it had no explaination of what any of the properties and methods did and its great someone put the time in to make it but a novice like me is struggling to come to terms with using a physics engine this complex so any other reading you could recommend would be grand.

Cheers people!

Clark.
Clark,

I'm working on something that's very similar to your goal - rolling a ball / wheel using keyboard input. Eventually, like you, I decided the best way to handle it was to have the keyboard alter the rotational velocity. The key part of the equation was giving the ball / wheel extremely high friction. This will eliminate the "wheelspin" you mentioned.

Additionally, when you press the arrow key in the opposite direction of the one you're moving in, it stops the ball / wheel right in it's tracks (like brakes) by setting the angular velocity to zero. It makes the ball / wheel feel very responsive.

I've posted a demo of what I'm working on here:

viewtopic.php?f=6&t=430

Warning: The high friction causes some weird effects, but for my simulation it just made things more fun 🙂

I've played with APE as well, but once I got over the learning curve of Box2D I never looked back...
Hey mate thanks for the reply.

Cool game! I see what you mean about friction having a weird side effect (you can roll up things) which may be undesirable for myself but certainly a step closer.

Cheers 😀
A little restitution to the ball should fix the wall problem.

Original thread: https://box2d.org/forum/viewtopic.php?t=501