-
The Cheeze to Your Macaroni
Problem with bounce physics
I am trying to get some decent bounce physics for a game that I am working on however the ball seems to never stop bouncing:
Ball Bounce Test
These are defined in another file
public static const FRICTION:Number = .5;
public static const WORLD_GRAVITY:Number = .3;
public static const WORLD_WIND:Number = .05;
Any ideas on how to fix this? Here is the code:
Code:
private function move():void{
//APLLY ALL FORCES TO THE GAME OBJECTS
//VELOCITY VARIABLE
//Apply gravity
redCircle.vY += Game.WORLD_GRAVITY;
redCircle.vX += Game.WORLD_WIND;
//redCircle.springToPoint(stage.mouseX,stage.mouseY);
//ADD NEW VELOCITY VECTOR TO COORDS
//Circle
redCircle.newX += redCircle.vX;
redCircle.newY += redCircle.vY;
//DO ANY TESTS THAT NEED TO BE DONE
//If circle hits ground reverse Y vel
//and apply friction
if(redCircle.newY >= Game.WORLD_GROUND){
redCircle.newY = 400;
redCircle.vY *= -1;
redCircle.vY *= redCircle.fr;
redCircle.vX *= redCircle.fr;
}
//Wrap circle around to other side
//when it hits the edge
var halfWidth:int = redCircle.width/2;
if(redCircle.newX > Game.STAGE_WIDTH + halfWidth){
redCircle.newX = 0 - halfWidth;
}
if(redCircle.newX < 0 - halfWidth){
redCircle.newX = Game.STAGE_WIDTH + halfWidth;
}
}//end move
-
FK founder & general loiterer
redCircle.vY *= -1;
should be something like redCircle.vY *= -0.6 that wil reduce the bounce
-
The Cheeze to Your Macaroni
Originally Posted by Flashkit
redCircle.vY *= -1;
should be something like redCircle.vY *= -0.6 that wil reduce the bounce
I did do that. It is afterwards.
redCircle.vY *= -1;
redCircle.vY *= redCircle.fr; //redCircle.fr == FRICTION:Number = .5;
-
FK founder & general loiterer
do a check for if the vy < say 0.2 vY = 0
-
Senior Member
You need to detect when the ball has become resting on the ground and stop adding gravity in such case.
*set up flag ballIsResting=false
*ball hits the floor
*reduce vY
*if vY < less then some number set vY=0 and set ballIsResting = true
*add gravity only if ballIsResting is false
-
the cheesy child
funny!!! I had the opposite problem. i wanted something (it wasn't a ball but it still worked) to continuously bounce. I have solved my problem but if you wnat i can give you my lower bounce script:
onClipEvent(load){
bounce = 10;
fullbounce = 10;
way = "down";
wtwo = _width/2;
htwo = _height/2;
speed = 10;
lr = 10;
take = 1.1;
wide = 550;
wide0 = 0;
moview = wtwo;
}
onClipEvent(enterFrame){
if(way=="down"){
_y+=bounce;
bounce+=1;
}else if(way=="up"){
_y-=bounce;
bounce-=take;
}
if(bounce<=0){
way = "down";
}
if(_root.ground.hitTest(_x,_y+htwo,true)){
way = "up";
}
}
make the walls or objects you are bouncing off into a movieclip called "ground".
what you need to do to mine to make the bounce lower every time is make the variable take higher. at the moment it is 1.1 but if you make it higher you'll lose your bounce and if you make it lower you'll gain bounce (which if that happens, something is wrong with the physics!)
please tell me if this worked!
-
Pumpkin Carving 2008
Originally Posted by tonypa
You need to detect when the ball has become resting on the ground and stop adding gravity in such case.
*set up flag ballIsResting=false
*ball hits the floor
*reduce vY
*if vY < less then some number set vY=0 and set ballIsResting = true
*add gravity only if ballIsResting is false
To do it quickly, false and true equate to 0/1, so just do:
Code:
vY *= gravity*ballIsResting;
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
@bounceboy: its not the first time you are bumping a dated thread- why dont you simply create new threads for the things you want to tell or share?
-
the cheesy child
ha! last time i did that everybody complained it was pointless to show so i asked for feedback and... you know where that went!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|