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

  • SEARCH
  • Home
  • 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 9235165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:57:43+00:00 2026-06-18T06:57:43+00:00

How do I create a body [A ball Body] that will bounce around the

  • 0

How do I create a body [A ball Body] that will bounce around the screen, never losing or gaining speed, regardless of what it hits in cocos2d-box2d?

  • 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-06-18T06:57:44+00:00Added an answer on June 18, 2026 at 6:57 am

    Set restitution of the fixture to 1, and friction to 0.

    Box2D manual says:

    Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. <…> A value of one means the ball’s velocity will be exactly reflected. This is called a perfectly elastic collision.

    A friction value of 0 turns off friction

    Without friction and with perfectly elastic collision your ball will bounce around the screen, never losing or gaining speed in a static environment. If environment is not static, then colliding with moving object will change speed of the ball.

    To solve this problem, I suggest next trick. Set contact listener, and in PostSolve method correct speed of you ball like this:

    void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
    {  
       if(contact->GetFixtureA()->GetBody() == YOUR_BALL_BODY ||
          contact->GetFixtureB()->GetBody() == YOUR_BALL_BODY)
       {
           float speed = YOUR_BALL_BODY->GetLinearVelocity().Length();
           float koef = YOUR_NEEDED_SPEED / speed;
           YOUR_BALL_BODY->SetLinearVelocity(koef * YOUR_BALL_BODY->GetLinearVelocity());
       }
    }
    

    How to set contact listener see there.

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

Sidebar

Related Questions

Posts.create({'body':post_body}); When I call that, Backbone will hit my sever with an AJAX post
I have code that has a ball bouncing around on a canvas I create
I'm trying to create a squishy ball with Cocos2d and Chipmunk (via SpaceManager) using
Basically I need to create a textarea that is character limited, but will have
Hey guys i have a question here, How do i create a body that
How to create a confluence macro with body that produces an inline output? The
I am trying to create a http body that I am going to pass
I'm trying to use stringbuilder to create a body of string to be used
can any body help me the create a menu(Home, My Quote, Send a Quote)
i want to create a new '.b' div appendTo document.body, and it can dragable

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.