Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Help with shooting arrows...

Discussion in 'Editor & General Support' started by tatelax, Feb 4, 2010.

  1. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,167
    what I have is a first person shooter. What I am shooting is arrows. When I shoot the arrow in one direction, it appears to be facing straight. when I am facing a different direction, it shoots it straight, but the arrow is facing sideways. This is very hard to explain lol. if I am facing one way it fires like a normal arrow, when i turn 90 degrees it shoot like this -----> but is going straight in front of me.. I hope I explained this good. Thanks!
     
  2. April

    April

    Joined:
    Dec 14, 2009
    Posts:
    62
    You are using world coordinates and not your arrow's coordinates.

    First we need to know what causes the arrow to shoot.
    If it is by adding force, maybe you are using the
    AddForce function. Look for it in your script and change it to AddRelativeForce.
     
  3. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,167
    var speed = 5.0;
    var rotateSpeed = 3.0;
    var bullitPrefab:Transform;

    function Update ()
    {
    var controller : CharacterController = GetComponent(CharacterController);
    transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
    var forward = transform.TransformDirection(Vector3.forward);
    var curSpeed = speed * Input.GetAxis ("Vertical");
    controller.SimpleMove(forward * curSpeed);

    if(Input.GetButtonDown("Jump"))
    {
    var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
    bullit.rigidbody.AddRelativeForce(transform.forward * 4000);
    }


    }
    @script RequireComponent(CharacterController)




    Heres the script that I am using...as you can see I did add the relative force. it didn't change anything. Can someone please help me thanks!
     
  4. April

    April

    Joined:
    Dec 14, 2009
    Posts:
    62
    hmmm.. the problem is because of this line

    var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);

    it says Quaternion.identity which means that the bullit
    instantiated will have no rotation at all;

    try replacing it with this.
    var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, transform.rotation);
     
  5. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,167
    Nope I did the change and its still not working. Anyone else have an idea
     
  6. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,167
    WAIT A MINUTE! WOOOHOOO I FIGURED IT OUT. You were right that was the problem. I just needed to flip the arrow around. When I first shot it it seemed like it didnt work. thank you so much!!!!!!
     
  7. Deleted User

    Deleted User

    Guest

  8. kayshahrul92

    kayshahrul92

    Joined:
    May 16, 2016
    Posts:
    1
    Hye there.you are still replying this?I would like to ask ffew things.can I?
     
unityunity