View Full Version : Help on a cricket Game.
acebuddy29
November 16th, 2007, 03:24 AM
Hi,
I am Planning on making a cricket game. And i need help on The physics of the ball. I am already working on it,but its kind of getting frustrating.Am trying to make something like this.
http://www.games2win.com/cricket/cricket_super_sixers.asp
If any body can point to some tutorial or something,will also be gr8.
Any sort of help would be really appreciated.
thank you.
Lou
November 16th, 2007, 06:30 PM
Hmm, I doubt that the game you linked uses real time physics at all. Did you want the game to be first person like that? That game is a few sets of frames for each result of where you player is when you hit the ball and how soon or late you try and hit the ball.
Here's a tut on basic gravity and bouncing:
http://www.kirupa.com/developer/actionscript/gravity.htm
Pretty much you set an acceleration and a starting velocity and have a friction subtract from the current speed. A simple hit test could be used in order to check if the ball hits the bat. If the player stays mostly stationary you could check if the bat hits the ball by when the key is pressed compared to where the ball is in the air.
Hope this makes some sort of sense, hopefully another forum dweller will come along with a better idea. If you still need some help I could make an example for you..
acebuddy29
November 26th, 2007, 12:40 AM
Hey Lou,first of all thanks for your reply. And yes you are right, it is not real time physics. But i would still like to develop something like tht using real time physics. Am sure its possible. anyways i started working on it and am posting the basic code that i wrote for bouncing the ball. i'll be working on it, so if nebody wants to help. You are most welcome.
var targetX:Number;
var targetY:Number;
var gravity = 1;
var focalLength = 100;
var speedX = 0;
var speedY = 0;
var bounce = .90;
var speedZ = 30
//origin.x = "372";
//origin.y = "134";
// We get the current time (still /100)
function handBall ()
{
ball.z = 100;
ball.dir = 21;
//getBallTarget (bat);
ball.onEnterFrame = function ()
{
this.z += speedZ * this.dir;
//trace (this.z);
if (this.z > 600)
{
this.z = 600;
this.dir = -1;
}
else if (this.z < 0)
{
this.z = 0;
this.dir = 1;
}
var scaleRatio = focalLength / (focalLength + this.z);
//this._x = origin.x+this.x*scaleRatio;
//this._y = origin.y+this.y*scaleRatio;*/
this._xscale = this._yscale = 100 * scaleRatio;
//trace (this._x);
if (this._y >= 310)
{
speedY *= -bounce;
}
speedY = gravity + speedY;
trace (speedY);
this._x += speedX;
this._y += speedY;
};
}
handBall ();
Just put a movie clip named ball on the stage. And i'll keep on updating this, as i progress.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.