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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:29:32+00:00 2026-05-18T12:29:32+00:00

** STILL NOT WORKING ** I am using below formula to move the ball

  • 0
                        ** STILL NOT WORKING **

I am using below formula to move the ball circular, where accelX and accelY are the values from accelerometer, it is working fine.

But the problem in this code is mRadius (I fixed its value to 50), i need to change mRadius according to accelerometer values and also i need bouncing effect when it touches the track. Currently i am developing code by assuming only one ball is on the board.

float degrees = -atan2(accelX, accelY);
int x = cCentrePoint.x + mRadius * cos(degrees);
int y = cCentrePoint.y + mRadius * sin(degrees);

Here is the snap of the game i want to develop:

Balls Game http://iphront.com/wp-content/uploads/2009/12/bdece528ea334033.jpg.jpg

Updated: I am sending the updated code…

 mRadius = 5;
 mRange = NSMakeRange(0,60);

-(void) updateBall: (UIAccelerationValue) accelX 
                                  withY:(UIAccelerationValue)accelY
{

    float degrees = -atan2(accelX, accelY);
    int x = cCentrePoint.x + mRadius * cos(degrees);
    int y = cCentrePoint.y + mRadius * sin(degrees);

    //self.targetRect is rect of ball Object
    self.targetRect = CGRectMake(newX, newY, 8, 9);
    self.currentRect = self.targetRect;

    static NSDate *lastDrawTime;

    if(lastDrawTime!=nil)
    {
       NSTimeInterval secondsSinceLastDraw =
                    -([lastDrawTime timeIntervalSinceNow]);

       ballXVelocity = ballXVelocity + (accelX * secondsSinceLastDraw) 
               * [self isTouchedTrack:mRadius andRange:mRange];
       ballYVelocity = ballYVelocity + -(accelY * secondsSinceLastDraw) 
               * [self isTouchedTrack:mRadius andRange:mRange];

      distXTravelled = distXTravelled + secondsSinceLastDraw
                          * ballXVelocity * 50;
      distYTravelled = distYTravelled + secondsSinceLastDraw 
                          * ballYVelocity * 50;

      //Updating the ball rect  
      CGRect temp = self.targetRect;
      temp.origin.x += distXTravelled;
      temp.origin.y += distYTravelled;

      //calculating new radius after updating ball position
      int radius = (temp.origin.x - cCentrePoint.x) / 
                               cos(degreesToRadians(degrees));

     if( !NSLocationInRange(abs(radius),mRange))
     {
         //Colided with the tracks...Need a better logic here
      ballXVelocity = -ballXVelocity;
     }
     else
     {
           // Need a better logic here
       self.targetRect = temp; 
     }

  }

  [lastDrawTime release];
  lastDrawTime = [ [NSDate alloc] init];
}

In the above code i have initialized mRadius and mRange(indicate track) to some constant for testing, i am not getting the moving of the ball as i expected( bouncing effect when Collided with track ) with respect to accelerometer. Help me to recognize where i went wrong or send some code snippets or links which does the similar job.

I am searching for better logic than my code, if you found share with me.

  • 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-18T12:29:33+00:00Added an answer on May 18, 2026 at 12:29 pm

    After trying alot I thought it is not easy to produce real time effect without using any physics engine. So its better to use BOX2d or Chipmunks or any other physics engines.

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

Sidebar

Related Questions

I'm still working on a particular RDF file, but seems that something is not
After reading Evan's and Nilsson's books I am still not sure how to manage
I just read the Wikipedia article on mock objects , but I'm still not
If not, is smoke testing still used?
I'm still having a hard time not wanting to use Tables to do my
Still 'diving in' to Python, and want to make sure I'm not overlooking something.
Not too practical maybe, but still interesting. Having some abstract question on matrix multiplication
I just wonder a bit whether or not GDI+ is still a technology worth
I am not sure if I formulated the question right, but still ... I
I still feel C++ offers some things that can't be beaten. It's not my

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.