Ball scripting

Hi, I’m developing a ball game and I ahve problems with ball moving script. I’ve tried rigidbody.AddForce, but then ball is constantly accelerating, adding torques, but it’s too slow and changing velocity, but it’s still imperfect.
Here’s the code:

var globalPoint : Transform;
var moveForce = 2.0;
var jumpForce = Vector3(0,5,0);


function OnCollisionStay(collision : Collision)
{
	if(collision.gameObject.tag!="NonJump"){
		if(Input.GetAxis("Horizontal")){
			rigidbody.velocity = globalPoint.right*Input.GetAxis("Horizontal")*moveForce;
		}
		if(Input.GetAxis("Vertical")){
			rigidbody.velocity = globalPoint.forward*Input.GetAxis("Vertical")*moveForce;
		}
		if(Input.GetButtonDown("Jump")||Input.GetButtonDown("Fire1")) {
			Jump(jumpForce);
		}
	}	
	
}
function Jump(force_of_jump)
{
	rigidbody.velocity += force_of_jump;
}

(Global Point is the point the camera is looking at useful for global axis declaration).

Have Yiu got any idea why is the ball moving so strangely?

I haven’t tested anything, but you might take a look at rigidbody.AddRelativeForce() and use a ForceMode of VelocityChange.

It says something about it doesn’t change the velocity based on mass, so if it’s time based, then I’m thinking it’s a constant speed with no acceleration.

-Raiden

Actually, it does not work. The problem is, that when force is acting on a bodfy, it accelerates constantly - it’s obvious. I’ve tried adding torque, but it’s far too slow. Is there a way to write such a controller in which ball will move precisely when keys are down and starting behaving physically when they are not?

Did you try turning on/off the rigidbody’s isKinematic property depending on whether you have the keyboard input?

If you want absolute control over the velocity, you need to compensate the current velocity of the body.

rigidbody.AddForce(-rigidbody.velocity + desiredVelocityVector, ForceMode.VelocityChange);

Perhaps you can describe exactly how the ball control works. Does the game involve hitting/kicking the ball? Once it is moving, is it out of the player’s control or is there some kind of “aftertouch” that can be applied to it?