Quantcast
Channel: Latest Questions by neejammer
Viewing all articles
Browse latest Browse all 8

How to Click to Move Sphere (With physics)?*

$
0
0
I have a basic click to move character controller script attached to a sphere. However, as it is now my sphere only moves around statically -like gliding across the floor. How do I get my script to make use of the 'Rigidbody' so my sphere rotates(moves) with the right physics? Or do you have any other solution? Help would be very very much appreciated"! I've been trying to find the answer to this for days now. Here is the ClickToMove script (http://wiki.unity3d.com/index.php/Click_To_Move) var smooth:int; // Determines how quickly object moves towards position private var targetPosition:Vector3; function Update () { if(Input.GetMouseButton(0)) { var playerPlane = new Plane(Vector3.up, transform.position); var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hitdist = 0.0; if (playerPlane.Raycast (ray, hitdist)) { var targetPoint = ray.GetPoint(hitdist); targetPosition = ray.GetPoint(hitdist); var targetRotation = Quaternion.LookRotation(targetPoint - transform.position); transform.rotation = targetRotation; } } transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth); }

Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>