Search Unity

Make my arrow go out straight?

Discussion in 'Scripting' started by ecloev, Oct 8, 2015.

  1. ecloev

    ecloev

    Joined:
    Oct 1, 2015
    Posts:
    101
    Hello,
    I would like to make my arrow shoot to my crosshair.
    Right now it is turned sideways. How can i get it's head to go like a normal arrow?

    PrefabShooting:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PrefabShooting : MonoBehaviour
    6. {
    7.     public Rigidbody theBullet;
    8.     public int speed = 65;
    9.  
    10.     void Update()
    11.     {
    12.         if (Input.GetMouseButtonDown(0))
    13.         {
    14.             Rigidbody clone = Instantiate(theBullet, transform.position, transform.rotation) as Rigidbody;
    15.             clone.velocity = transform.TransformDirection(Vector3.forward * speed);
    16.  
    17.             Destroy(clone.gameObject, 3);
    18.         }
    19.     }
    20. }
    21.  
    ArrowDamage:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class ArrowDamage : MonoBehaviour {
    6.     public int Damage = 25;
    7.  
    8.     void OnCollisionEnter(Collision info) {
    9.         info.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
    10.     }
    11. }
    12.  
    13.  
     
  2. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    I guess if you use
    Code (CSharp):
    1. transform.Translate(Vector3.forward * Time.deltaTime * movementSpeed);
    it will be better.

    If that does not fix the issue, I'd suggest you to look up the transform.rotation of the current object your script is attached to, as you're getting its transform.rotation to pass through to the clone. Make sure that the gameobject the script is attached to has the right sides, meaning its left is not back, and right is not forward etc!

    Some gameobjects, or better to say the actual models are modeled poorly, which results in issues like that! Or else, you can also use a parent gameobject in order to get the correct rotation.