collision after "Click to Move"


I use the "click to move" script from Unify Wiki for the (main) sphere movement, like for billiard : OK and great !!! But I would like this sphere collide with another spheres (with colliders !) and each one rolls in "logical" directions : after two (or more) "spheres" collisions ! Could you help me with the script, please ? (javascript)



You probably want to ignore the idea of interpolation all together and rely on physics for this task. I still take it you want to add force toward the point you click.

@script RequireComponent(Rigidbody)

var strength : float = 10.0f;

function Update () 
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        var hit : RaycastHit;

        if (Physics.Raycast(ray, hit)) 
            var delta = hit.point - transform.position;
            rigidbody.AddForce(delta.normalized * strength, ForceMode.Impulse);

This script is similar to click to move but it uses physics instead. If you are having problems with that the balls are jumping around when clicking near (or even on them), you could set "delta.y = 0;" before AddForce is called. This will ignore height force.

Your spheres (all of them) require now a rigidbody and your ground require a collider.

Happy coding.

Thanks a lot Statement,

Very helpful script. There are some strange behaviours but I will try to change some parameters here and there.