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:
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.
I have the code that if it hits a left wall for example it multiples xmove by -1
i have no idea whats wrong :’(
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.
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
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
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…
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]
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
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
anyone :’( ?
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