Hey,
I am creating a 2.5D marble roller game. I have made a script, but it is not working perfectly, the marble is not rolling, and it is hard to controll.
Here is the script:
var speed : float = 1.0;
var maxSpeed : float = 3.0;
var position : Vector3;
var cube : GameObject;
var curSpeed : float = 0.0;
function Update ()
{
if(Input.GetMouseButton(0))
{
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
position.x = hit.point.x;
position.y = 0;
position.z = hit.point.z;
}
if (curSpeed < maxSpeed)
rigidbody.AddTorque(position.x * speed * Time.deltaTime, 0, position.z * speed * Time.deltaTime);
}
curSpeed = Vector3(rigidbody.velocity.x, 0, rigidbody.velocity.z).magnitude;
}
The scene contains the following:
A scaled cube for the ground.
A sphere with a rigidbody, physics material, and the script.
Can you give me some advice, to improve it to be better?
Thanks!