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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:44:46+00:00 2026-05-11T20:44:46+00:00

I’d like to deflect a ball at an angle depending on where it hits

  • 0

I’d like to deflect a ball at an angle depending on where it hits a paddle. Right now, I’m only changing the y coordinate, which results in an uninteresting deflection. It will angle but independent on impact location against the paddle. I’d like something more fun. Speed, momentum, mass and other factors don’t need to be taken into consideration. Just angle depending on impact location of paddle. I’ve read this Not a number error (NAN) doing collision detection in an iphone app but it seems overly complicated for what I’m looking for. Is there a simpler way to calculate the deflection?

The objects are two UIImageViews.

  • 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-11T20:44:47+00:00Added an answer on May 11, 2026 at 8:44 pm

    Well, nothing realistic but you could do something so that the outbound angle is only dependent on where on the paddle it hits.

    I have never done any iPhone or objective C coding so I’ll just write up something in pseudo/C code.

    First I’d calculate the speed, which is the length of the speed vector, or:

    double speed = sqrt(velX * velX + velY * velY); // trigonometry, a^2 + o^2 = h^2
    

    Then we want to calculate the new angle based on where we hit the paddle. I’m going to assume that you store the X collision in impactX and the length of the paddle in paddleLength. That way we can calculate an outbound angle. First let’s figure out how to calculate the range so that we get a value between -1 and 1.

    double proportionOfPaddle = impactX / (double) paddleLength; // between 0 and 1
    double impactRange = proportionOfPaddle * 2 - 1; // adjust to -1 and 1
    

    Let’s assume that we do not want to deflect the ball completely to the side, or 90 degrees, since that would be pretty hard to recover from. Since I’m going to use the impactRange as the new velY, I’m going to scale it down to say -0.9 to 0.9.

    impactRange = impactRange * 0.9;
    

    Now we need to calculate the velX so that the speed is constant.

    double newVelX = impactRange;
    double newVelY = sqrt(speed * speed - newVelX * newVelX); // trigonometry again
    

    Now you return the newVelX and newVelY and you have an impact and speed dependent bounce.

    Good luck!

    (Might very well be bugs in here, and I might have inverted the X or Y, but I hope you get the general idea).

    EDIT: Adding some thoughts about getting the impactX.

    Let’s assume you have the ball.center.x and the paddle.center.x (don’t know what you call it, but let’s assume that paddle.center.x will give us the center of the paddle) we should be able to calculate the impactRange from that.

    We also need the ball radius (I’ll assume ball.width as the diameter) and the paddle size (paddle.width?).

    int ballPaddleDiff = paddle.center.x - ball.center.x;
    int totalRange = paddle.width + ball.width;
    

    The smallest value for ballPaddleDiff would be when the ball is just touching the side of the paddle. That ballPaddleDiff would then be paddle.width/2 + ball.width/2. So, the new impactRange would therefore be

    double impactRange = ballPaddleDiff / (double) totalRange / 2;
    

    You should probably check the impactRange so that it actually is between -1 and 1 so that the ball doesn’t shoot off into the stars or something.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have text I am displaying in SIlverlight that is coming from a CMS
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.