- Home /
Vector3 to Float? Trying to accomplish a MouseDrag..
I'm trying to archive to shoot a proyectile based on the Mouse Movement (not related to the world, so no raycasts :(
How can I make it so that my mouse position gets converted into a float_>?? I looked into mousedrag, but frankly i havent gotten it after alot of googling.
if(Input.GetKey(KeyCode.V)){
var dragAmount : Vector3;
Debug.Log("Aim and shot");
if(Input.GetMouseButtonDown(0)){
firstPosit = Input.mousePosition;
}
if(Input.GetMouseButtonUp(0)){
lastPosit = Input.mousePosition;
}
dragAmount = lastPosit-firstPosit;
Convert dragAmount into a float?????????????????????
Debug.Log( "delta X : " + lastPosit.x);
Debug.Log( "delta Y : " + lastPosit.y);
thanks guys.
If you mean the length of the vector, then you need to start applying some of the trigonometry you've (hopefully) been taught in high-school. Just calculate the distance between the two points on the x-y plane using the pythagorean theorem. That is, the distance between (firstPosit.x,firstPosit.y) and (lastPosit.x, lastPosit.y).
Answer by AlucardJay · May 06, 2014 at 02:14 PM
You want the distance of the drag?
http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Distance.html
var dist = Vector3.Distance(lastPosit, firstPosit);
note : this will give you a value in screen pixels when using Input.mousePosition
Your answer
Follow this Question
Related Questions
Raycast hitting below mouse position :( 0 Answers
Having player object always snap to mouse position 1 Answer
Scale a 2D object based on mousePosition on click 1 Answer
How to shoot a puck straight? (JS) 0 Answers
3D Shoot at mouse position. 0 Answers