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 6039593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:23:31+00:00 2026-05-23T06:23:31+00:00

i have 2 sprites that moving horizontly and i need them to fall down

  • 0

i have 2 sprites that moving horizontly and i need them to fall down naturally ,when they hit a wall .
i know how to do that in a simple way of changing position every frame, but this is not seems natural, and probably not the right way.

There is a way to discover the collision and then make them fall down, when thier speed and y axis is taking into consideration ?

i just couldnt find a simple way to do that with box2d or chipmunk .

any direction would be great.
thanx.

  • 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-23T06:23:32+00:00Added an answer on May 23, 2026 at 6:23 am

    Firstly add a custom contact listener to your b2World.

    public class Main
    {
          public function Main()
          {
                //init stuff
                var cc:CustomContactListener = new CustomContactListener();
                world.setContactListener(cc);
          }
    }
    
    //then on hit call the hit function on sprite
    public class CustomContactListener extends b2ContactListener
    {
          //Called when a contact point is added.
          public override function Add(point:b2ContactPoint):void 
          {
                //checks if the first shape is a sprite and second is a wall if true call Hit
                if (point.shape1.GetBody().GetUserData().isSprite && point.shape2.GetBody().GetUserData().isWall)
                {
                     point.shape1.GetBody().GetUserData().Hit();
                }
                else if (point.shape2.GetBody().GetUserData().isSprite && point.shape1.GetBody().GetUserData().isWall)
                {
                     point.shape2.GetBody().GetUserData().Hit();
                }
          }
    }
    
    
    public class Sprite
    {
          public var hit:Boolean = false;
    
          //Set hit to true and start applying realistic downward force
          public function Hit()
          {
               hit = true;
          }
    
          //Enter frame event that applies force
          public function step(e:Event)
          {
               if (hit)
               {
                     b2Vec2 force = new b2Vec2(0, -9.8);
                     bodyOfSprite.ApplyLinearForce(force);
               }
          }
    }
    

    This relies on you setting the userdata of all the bodies you have as the class that holds it. i.e. Sprite, Wall. You could also do it the opposite way where you apply gravity all the time and also apply an opposing force. Then when you make contact with the wall you stop applying the other force and gravity takes effect.

    Or like how @iforce2d puts it just check when the linearvelocity of the body of the sprite is close or equal to zero because that would indicate it has hit something that has stopped it, not just a wall though, then you can just set hit to true. And the step function will do the rest. This is limited though because it just needs it to slow down to trigger it not hit a wall which may not be desired.

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

Sidebar

Related Questions

I have an image file that has all the character sprites that I will
I have written code that automatically creates CSS sprites based on the IMG tags
I am using andengine and I have some sprites that change color when pressed.
i have a cocos2d world, and a sprite/body that is moving fast . when
I am using Sparrow framework. I have been playing with moving sprites around using
If I have a simple class that has a rectangle: package { import flash.display.Sprite;
I have moving sprites in my game and have added labels on it (CCLabelTTF).
I have a webpage that uses sprites for its navigation link. In IE7 sometimes
i have an app using cocos2d, Im moving some sprites and having animations when
I have some sprites that the users can manipulate, drag around and resize. Now

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.