Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4044090
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:12:35+00:00 2026-05-20T13:12:35+00:00

Been struggling with this for a couple of days, hard to find code examples

  • 0

Been struggling with this for a couple of days, hard to find code examples on the net.

I’m making a topdown game and having trouble getting the player to move on key press. At the moment i’m using add_force or add_impulse to move the player in a direction, but the player doesn’t stop.
I’ve read about using surface friction between the space and the player to simulate friction and here is how it’s done in the tank.c demo.

However I don’t understand the API enough to port this code from chipmunk into pymunk.

cpConstraint *pivot = cpSpaceAddConstraint(space, cpPivotJointNew2(tankControlBody, tankBody, cpvzero, cpvzero));

So far, I have something that looks like this:

class Player(PhysicalObject):
    BASE_SPEED = 5
    VISIBLE_RANGE = 400
    def __init__(self, image, position, world, movementType=None):
        PhysicalObject.__init__(self, image, position, world)
        self.mass = 100
        self.CreateBody()
        self.controlBody = pymunk.Body(pymunk.inf, pymunk.inf)
        self.joint = pymunk.PivotJoint(self.body, self.controlBody, (0,0))
        self.joint.max_force = 100
        self.joint.bias_coef = 0
        world.space.add(self.joint)

I don’t know how to add the constraint of the space/player to the space.

(Need someone with 1500+ rep to create a pymunk tag for this question).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:12:36+00:00Added an answer on May 20, 2026 at 1:12 pm

    Joe crossposted the question to the Chipmunk/pymunk forum, and it got a couple of more answers there. http://www.slembcke.net/forums/viewtopic.php?f=1&t=1450&start=0&st=0&sk=t&sd=a

    Ive pasted/edited in parts of my answer from the forum below:

    #As pymunk is python and not C, the constructor to PivotJoint is defined as
    def __init__(self, a, b, *args):
        pass
    
    #and the straight conversion from c to python is
    pivot1 = PivotJoint(tankControlBody, tankBody, Vec2d.zero(), Vec2d.zero())
    # but ofc it works equally well with 0 tuples instead of the zero() methods:
    pivot2 = PivotJoint(tankControlBody, tankBody, (0,0), (0,0))
    
    mySpace.add(pivot1, pivot2)
    

    Depending on if you send in one or two arguments to args, it will either use the cpPivotJointNew or cpPivotJointNew2 method in the C interface to create the joint. The difference between these two methods is that cpPivotJointNew want one pivot point as argument, and the cpPivotJointNew2 want two anchor points. So, if you send in one Vec2d pymunk will use cpPivotJointNew, but if you send in two Vec2d it will use cpPivotJointNew2.

    Full PivotJoint constructor documentation is here: PivotJoint constructor docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with this one for a couple of days now. My current
I've been struggling with this issue for a couple of days now. I need
I've been struggling for a couple of days now with this problem on QTcpSockets
I've been struggling with some code for a paging for a couple of days
I've been struggling with this for a couple days now. I'm trying to make
Been struggling with this for a couple days now. Here's the set up -
So I've been struggling with this for the last couple days.. I have music
I've been struggling with this for a couple of hours now and I simply
Been struggling with this simple selector problem a couple of hours now and must
Ive been struggling with this all day, been close a couple times but nothing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.