- Home /
Question by
givaway · Apr 25, 2012 at 05:58 AM ·
mouse positionlinecastlength
increase linecast length
Im creating a 2d game where a player points at objects to shoot at them but i want to use linecast instead of bullets. im trying to increase the length of the raycast so the player only hast to aim in the direction but when i multiply the end position it loses accuracy.
heres my code:
#pragma strict
var AttachedCamera:Camera;
function Start () {
}
function Update ()
{
var MousePosition = this.AttachedCamera.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y,Mathf.Abs(this.transform.position.z + this.AttachedCamera.transform.position.z)));
var hit:RaycastHit;
if (Physics.Linecast (this.transform.localPosition, MousePosition - (), hit)) {
if(Input.GetMouseButton(0))
{
Debug.DrawLine(transform.position, hit.point, Color.red,10);
Destroy(hit.collider.gameObject);
}
Debug.DrawLine(transform.position, hit.point, Color.blue);
}else
{
Debug.DrawLine(transform.position,MousePosition, Color.green);
//Debug.DrawLine(transform.position, MousePosition + MousePosition, Color.cyan);
}
}
How can i extend the length without losing accuracy? thanks in advance
Comment
Your answer
Follow this Question
Related Questions
!(not)Linecast not working _but Linecast works 2 Answers
[2D] Check if player is on the ground 4 Answers
Calculating angle using a raycastHit2D 1 Answer
RayCast or LineCast? 1 Answer
Playing a different audio clip after another has finished 1 Answer