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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:36:10+00:00 2026-06-18T03:36:10+00:00

It seems so simple to me, but my solution doesn’t work. I’ve made a

  • 0

It seems so simple to me, but my solution doesn’t work. I’ve made a small program, my biggest and most advanced program, but still a small one. All it is is a ball that bounces off the floor and slowly runs out of energy. I’ve made it able to restart its bouncing by pressing SPACE and it can change direction by pressing the arrow keys, using a very simple velocity calculation(extremely simple actually).

Here’s my problem, I’m very new to programming, this is only my second day, and I need a way to bounce the ball off the side walls of the stage.

onClipEvent(load){
velocity = 0 //Vertical Velocity, is increased and decreased by the effects of gravity and bouncing with SPACE
sideVel =0 //Side Velocity, increases when the arrow keys are pressed, decreases over time
gravity = 2 //Gravity, constant force that never changes
}
onClipEvent(enterFrame){
_x += sideVel //Moves the ball the value of Side Velocity
if (Key.isDown(Key.LEFT)) {
    sideVel -= 2 //Technically decreases Side Velocity, but really increases it in another direction
}
else {
    if(sideVel<0) { //If the button isn't being pressed Side Velocity returns to 0 over time
    sideVel += 1
    }
}
if (Key.isDown(Key.RIGHT)) {
    sideVel += 2 //Increases Side Velocity
}
else {
    if(sideVel>0) //If the button isn't being pressed Side Velocity returns to 0 over time
    sideVel -= 1
}
if (sideVel < -20){ //Side Velocity isn't allowed to go below this number
    sideVel +=2 //So we add 2
}
if (sideVel > 20) { //Same as above
    sideVel -=2
}
velocity += gravity //Regular Velocity increases by 2 every frame
_y += velocity //mcMain moves at the speed of its velocity
if(_y>=Stage.height){
if(Key.isDown(Key.SPACE)){
    velocity=-28 //Sets Velocity to -28, pretty much the same as doing a jump
}
else {
_y = Stage.height
velocity *= -0.9 //Reverses mcMain's velocity, so it bounces back into the air at a slightly slower speed
}
/*Here's the problem
if(_x>=Stage.width - 25){
    _x=Stage.width - 25
sideVel *= -1
}
if(_x<=Stage.width - 550){
    _x=Stage.width - 550
sideVel *= -1
}
}
}
  • 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-18T03:36:11+00:00Added an answer on June 18, 2026 at 3:36 am

    You have to manually change the position of the MC (MC.x++ and whatnot) when it hits the wall so that the collision doesn’t register multiple times. Also, using while statements in place of if for the wall collisions will ensure that the ball doesn’t pass through the wall.

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

Sidebar

Related Questions

This seems like it should have such a simple solution, but apparently it doesn't.
This seems like such a simple issue but I cannot find an elegant solution.
This seems a ridiculously simple question to be asking, but what's the shortest/most idiomatic
I'm pretty sure there is a very simple solution here but I can't seem
This seems simple but I've exhausted my Google search patience. I have a RelativeLayout
This seems simple but I can't figure it out. I receive post data in
I'm stuck with a certain query, it seems to be simple but it seems
Seems simple, but not for me. I can get the current year with: <jsp:useBean
That seems simple enough, but all Django Queries seems to be 'SELECT *' How
This seems like it should be very simple but I can't get it to

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.