Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin joints don't hold bodies in fixed positions #213

Open
fr0zi opened this issue Nov 5, 2021 · 4 comments
Open

Pin joints don't hold bodies in fixed positions #213

fr0zi opened this issue Nov 5, 2021 · 4 comments

Comments

@fr0zi
Copy link

fr0zi commented Nov 5, 2021

Hi. This is probably not a bug but I couldn't register on the forum to ask my question (I didn't get an email for account activation) so I will ask here.

I'm working on top-down vehicle simulation game and I want to build a vehicle with physical body as chassis and also physical bodies for wheels. Wheels are connected to chassis body with pin joints. However when I run the game and try to drive a vehicle, wheels are wiggling and front wheels don't hold their positions relative to the chassis. Like in the video below:

vehicle_joints.mp4.mp4

Chassis body has a mas of 10 and wheels - mas of 1.

I have a fixed step for physics implemented and it should be fine since I used similar code in some of my previous projects where I used Bullet Physics and it was working fine.

Is there a way to fix wheels to stay in correct positions, as wheels should, or it's just how they work in Chipmunk?

Thanks in advance for help.
And thanks for making Chipmunk :) I like it and I hope I will be able to use it in my game.

@aismann
Copy link
Contributor

aismann commented Nov 6, 2021

Maybe an easier way to simulate the wheels:
Use only:
cpVect cpBodyGetVelocity(const cpBody *body)
void cpBodySetVelocity(cpBody *body, const cpVect value)

And the wheels will be only draw like a sprite without physics behavior. (If you see the weels on screen)

@fr0zi
Copy link
Author

fr0zi commented Nov 6, 2021

The problem is - I want to make it simulation-ish, not arcade and I want to make wheels to steer and drive the vehicle :) I know that it's possible to achieve with Box2d but I wanted to try with Chipmunk first because I like the API and simplicity. Question is if joints in Chipmunk are able to provide correct behaviour in this case?

@aismann
Copy link
Contributor

aismann commented Nov 6, 2021

Ok.
You know each wheel is only a point (line) contact on the street?
The direction can be simulate with the direction of the velocity.
So maybe you can try to simulate without draw of two boxes which 'show' the wheel as a top view of a wheel (not the contact on the street)

@fr0zi
Copy link
Author

fr0zi commented Nov 6, 2021

I don't think I'm following. These boxes drawn in place of wheels are just debug shapes of the wheel shapes. Wheels itself are normal physical bodies and I want to make it this way.

Anyway, I maybe found the reason for my problem with joints. I realized that to prevent vehicle to slide to the sides, I killed lateral velocity completely, so I suppose in some cases joints were forced to move from it's anchor point. I changed my calculation and now I'm killing only like 90% of lateral force, giving wheels possibility to adjust their positions a little bit, and now they behave correctly. At least it seems so for now. Issue can be closed.

Thanks for answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants