Search Unity

raycast DrawLine wrong direction, please help

Discussion in 'Editor & General Support' started by maubar, Oct 12, 2015.

  1. maubar

    maubar

    Joined:
    May 27, 2015
    Posts:
    128
    hi. i have a basic code in java, to shoot in a game using raycast
    and all the code works great, but when i try to draw a line when shoot in editor
    the line appear in other direction.....
    please how to fix this on line 27 on my code.
    please help.... thanks a lot.

    Code (JavaScript):
    1.  var Effects: GameObject;
    2. var initialSpeed = 20.0;
    3. var TheDamage = 100;
    4. var projectile: Rigidbody;
    5.  
    6.  
    7. function Update () {
    8.  
    9.     var hit : RaycastHit ;
    10.     var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
    11.  
    12.     if (Input.GetMouseButtonDown(0))
    13.     {
    14.  
    15.     GetComponent.<AudioSource>().Play();
    16.  
    17.     var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
    18.     instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (5, 0, initialSpeed));
    19.  
    20.         if (Physics.Raycast (ray,hit,100))
    21.         {
    22.        
    23.             var particleClone = Instantiate (Effects, hit.point, Quaternion.LookRotation(hit.normal));
    24.             Destroy(particleClone.gameObject, 5);  // espera 5 segundosay destruye
    25.             hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
    26.        
    27.             Debug.DrawLine (ray.origin, hit.point);
    28.        
    29.         }
    30.     }
    31.  
    32.  
    33. }
    by the way ....
    how can I draw a line rendered in the game please ?
    thanks
     
    Last edited: Oct 13, 2015
  2. maubar

    maubar

    Joined:
    May 27, 2015
    Posts:
    128
    please help
    thanks