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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:30:13+00:00 2026-06-13T16:30:13+00:00

In my 2D game I have the hero and coins that appear randomly. When

  • 0

In my 2D game I have the hero and coins that appear randomly. When the hero gets a power-up, his velocity increases so he flys faster. Power-up is active for 10 seconds. When the powerup is active, if he is close to coins, coins should follow and collide with him like in Temple Run. I am not using any box2d type physics. For collision, I am using rectangular intersection checks and collision is not the problem here.

How do I achieve this effect of coins to follow the hero like magnets?

My current implementation is – check the distance between each coin in the coin group and the hero. If the target distance for coin movement is satisfied, change the coin’s velocity on x based the on the velocity of the hero but this is not working as expected. How do I apply the impulse?

  • 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-13T16:30:15+00:00Added an answer on June 13, 2026 at 4:30 pm

    Change it to work on the inverse of the distance. For reference, Newton’s (mostly correct) law of Universal Gravitation:

    Where F is the force, G is some constant, r is the radius (the seperation distance), m1 is the mass of the coin, and m2 is the mass of the hero.

    We also know Newton’s Second Law of Motion:

    Where F is the force, m is the mass of the coin, and a is the acceleration of the coin.

    We can combine those two equasions to get:

    From there, we know that the hero’s “mass” is going to be proportional to the hero’s area (2D objects don’t really have mass but let’s just pretend for a second), in other words:

    Assuming you’re scaling your hero equally in all directions, this means that the “mass” of your hero will be proportional to the square of the size scale factor S, like so:

    This all boils down to:

    Where a is the acceleration (the quantity you’re looking for), S is the scale factor of the hero size, d is the distance from the hero to a coin, and k is a constant factor (just fudge it until coins move the right speed).

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

Sidebar

Related Questions

In my game I have a concept of resource manager, a class that stores
I have a game where user controls a character (with his finger) and i
In my number game children have 30 seconds to shoot the number icons that
Im creating flash game that have the functionality to capture/record its gameplay that can
In my game I have a header file that contains properties and functions for
While developing a game I have designed a class that in normal operation has
I have the Problem that a quite simple select (SELECT h FROM Hero h
I have a silly little game that I made just for myself, but I
I am making a game and I have my hero and enemy. Now I
My game units have an angle variable, and a targetAngle variable. These variables range

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.