- Home /
How to make this script work on a other axis?
I found this script, that does that the obbject follows the mouse on the x axis, when you move the mouse side to side on drag. How do i make the script, so it follows the mouse on not only the x axis but also the y axis? I know how to script, but i just cant figure this out.
function OnMouseDrag() { point = Camera.main.ScreenToWorldPoint( Vector3( Input.mousePosition.x, (transform.position.y-Camera.main.transform.position.y), (transform.position.z-Camera.main.transform.position.z)));
point.y = transform.position.y;
point.z = transform.position.z; transform.position = point; }
Answer by Swaggre · May 03, 2014 at 01:02 PM
var distance : int;
var smooth : int;
private var targetPosition : Vector3;
function Update () {
var playerPlane = new Plane(Vector3.up, transform.position);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var targetPoint = ray.GetPoint(distance);
targetPosition = ray.GetPoint(distance);
transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * smooth);
}
If you want to drag with mouse just add if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.$$anonymous$$ouse0)){ } for example
Your answer

Follow this Question
Related Questions
How do I get my raycast to stop projecting from the middle? 0 Answers
How do I add a plane to every triangle in a mesh? 2 Answers
Have camera go to dolly points with code? 1 Answer
How to drag mouse on circular arrow 1 Answer
Door scripts. 1 Answer