# Bouncing problem with my golf game :(

**URL:** <https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162>\
**Category:** Uncategorized\
**Created:** [February 5, 2004, 10:06pm UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162 "2004-02-05T22:06:31Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elbudster](https://avatars.discourse-cdn.com/v4/letter/e/a698b9/32.png) [@Elbudster](https://forum.kirupa.com/u/Elbudster)\
**Post date:** [February 5, 2004, 10:06pm UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/1 "2004-02-05T22:06:31Z")

</div>

I have got a problem with the little golf game I am making. It’s still pretty early and I haven’t coded some things but the ball does not bounce when it hits the wall. It kind of like rolls along the side. I’ve attached the .fla for MX If anyone could help me figure out why the ball does not bounce, I would love yew :love:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 5, 2004, 10:22pm UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/2 "2004-02-05T22:22:44Z")

</div>

Didn’t get a chance to look at it too much… But I’m going to take a guess that your movement variable needs to be flipped.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 12:02am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/3 "2004-02-06T00:02:50Z")

</div>

I have the code that if it hits a left wall for example it multiples xmove by -1

i have no idea whats wrong :’(

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 6, 2004, 9:40pm UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/4 "2004-02-06T21:40:39Z")

</div>

Hmm… Make sure that the ball isn’t going “in” the wall then… If if goes into the wall… It may keep testing that and keep rotating it around… Everytime the ball hits a wall. If it is on the left… Maybe jerk the ball out a little to the right after it hits the wall. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2004, 12:02am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/5 "2004-02-07T00:02:49Z")

</div>

Thats exactly what I was thinking it was doing. That is a good idea about shooting it out a little. I have been trying to use a setInterval so that it won’t hitTest for about a second or so that way itll have time to leave.

Needless to say I didn’t get that to work 😛

I’ll try your idea quick

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2004, 12:09am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/6 "2004-02-07T00:09:43Z")

</div>

Alright I just tried that and when it hit the left wall I set it so that the \_x would be += to 100. It would hit the wall and then move out the 100 then would continue to go back in the direction and “hump” the wall yet again 😑

Do you think it would have something to do with the formula I am using?

scale is a variable for the power of the ball, ball is the movie clip where xmove and ymove are stored…

[AS]  
speed = scale/5;  
\_root.ball.xmove = Math.cos(angle)\*speed;  
\_root.ball.ymove = Math.sin(angle)\*speed;  
[/AS]

It’s really starting to get annoying now 😑

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2004, 1:30am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/7 "2004-02-07T01:30:25Z")

</div>

I don’t think it has anything to do with your formula there… I haven’t done cos and sin in a while for games… But I know that should be correct… (thinks about it for a minute)… Yes… That is correct…

So… Hmm… Post some more code… I’d look at the file… But I’m working on literally 3 things right now… 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2004, 1:43am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/8 "2004-02-07T01:43:02Z")

</div>

Roger that… I’ll post all the code 🙂

Code for the arrow(gauge)  
[AS]  
onClipEvent (load) {  
this.\_visible = 0;  
fire;  
scale = 0;  
powerpick = 0;  
anglepick = 0;  
angle = 0;  
speed = 0;  
}  
onClipEvent (enterFrame) {  
if (\_root.ball.spot == 1) {  
this.\_visible = 1;  
this.\_x = \_root.ball.\_x;  
this.\_y = \_root.ball.\_y;  
if (powerpick == 0) {  
scale = \_root.\_xmouse - \_root.ball.\_x;  
if (scale \> 40) {  
scale = 40;  
}  
if (scale \< 5) {  
scale = 5;  
}  
this.\_xscale = scale;  
speed = scale/5;  
}  
if (powerpick == 1 and anglepick == 0) {  
var dx = \_parent.\_xmouse - this.\_x;  
var dy = \_parent.\_ymouse - this.\_y;  
angle = Math.atan2(dy, dx);  
this.\_rotation = angle\*180/Math.PI;  
}  
if (fire == 1) {  
this.\_visible = 0;  
\_root.ball.xmove = Math.cos(angle)\*speed;  
\_root.ball.ymove = Math.sin(angle)\*speed;  
speed -= .05;  
if (speed \< 0) {  
speed = 0;  
fire = 0;  
}  
}  
}  
}  
[/AS]

Code on the ball  
[AS]  
onClipEvent (load) {  
spot = 0;  
this.\_x = \_root.base.\_x;  
this.\_y = \_root.base.\_y;  
xmove = 1;  
ymove = 1;  
}  
onClipEvent (enterFrame) {  
//initial ball location  
if (spot == 0) {  
if (xmove = 1) {  
this.\_x = \_root.\_xmouse;  
}  
if (ymove = 1) {  
this.\_y = \_root.\_ymouse;  
}  
if (this.\_x \< 38) {  
xmove = 0;  
this.\_x = 38;  
}  
if (this.\_x \> 72) {  
xmove = 0;  
this.\_x = 72;  
}  
if (this.\_y \< 38) {  
ymove = 0;  
this.\_y = 38;  
}  
if (this.\_y \> 102) {  
ymove = 0;  
this.\_y = 102;  
}  
}  
//wall hitTests  
if (this.hitTest(\_root.left1) || this.hitTest(\_root.left2) || this.hitTest(\_root.left3)) {  
xmove \*= -1;  
}  
if (this.hitTest(\_root.right1)) {  
xmove \*= -1;  
}  
if (this.hitTest(\_root.top1) || this.hitTest(\_root.top2)) {  
ymove \*= -1;  
}  
if (this.hitTest(\_root.bottom1) || this.hitTest(\_root.bottom2)) {  
ymove \*= -1;  
}  
if (\_root.gauge.fire == 1) {  
this.\_x += xmove;  
this.\_y += ymove;  
}  
}  
onClipEvent (mouseDown) {  
if (\_root.gauge.powerpick == 1) {  
\_root.gauge.anglepick = 1;  
\_root.gauge.fire = 1;  
}  
if (\_root.gauge.powerpick == 0 and spot == 1) {  
\_root.gauge.powerpick = 1;  
}  
if (spot == 0) {  
spot = 1;  
mouse.hide();  
}  
}  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2004, 1:55am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/9 "2004-02-07T01:55:41Z")

</div>

Okay… Let’s address things problem by problem…

First problem…

//initial ball location  
if (spot == 0) {  
if (xmove = 1) {  
this.\_x = \_root.\_xmouse;  
}  
if (ymove = 1) {  
this.\_y = \_root.\_ymouse;  
}

That should have == instead of = in the if statement causes… See if that helps out any

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 7, 2004, 2:46am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/10 "2004-02-07T02:46:47Z")

</div>

omg thats weird… when i put the == in the statements there the initial ball placement doesn’t work 😑 but it works right with just = there… doesn’t solve the problem though ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2004, 3:14am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/11 "2004-02-09T03:14:03Z")

</div>

anyone :’( ?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2004, 3:38am UTC](https://forum.kirupa.com/t/bouncing-problem-with-my-golf-game/42162/12 "2004-02-09T03:38:39Z")

</div>

There is something obvious I’m overlooking then… So… I’m going to let someone else ook at the code… Because. It’s probably obvious…But my brain has been racked over 20 different things today… Sorry bud 🙂
