instantiated prefab doesn't follow spawn rotation
Hey all I'm new to scripting and unity. I was following a tutorial on youtube about making a bow shoot an arrow with arrowspawn.
this one: https://www.youtube.com/watch?v=ayiXNHhUhQE&t=201s
Now the problem that I'm having (and this guy appearently not) is that my arrow spawns in at the same rotation as the asset has been imported as. So it doesn't follow the rotation of the spawnpoint or camera. I already checked the whole forum but I can't understand 90% of it. Can someone help me with this please?
shoot script:
arrow script
Answer by Drislak · Apr 01, 2020 at 10:44 AM
Hi @Fuzzyleon, as you're not familiar with coding nor Unity, I'll first give you a direction on where to look, please continue reading after looking for the possible solution yourself. Please take a look at your Arrow.cs Update() method to see if anything there doesn't make sense.
I hope you've analyzed your code for a while, and came to the conclusing that you forgot to put "!" at the start of your If-statement. This is important as it will flip the condition you are checking after, in this case you're checking a boolean to see if you hit something. By putting the "!" in front of this, you flip that to check if you did NOT hit anything.
If I could give you one tip, look into videos from more experienced coders and do not following along videos without trying to understand what you're doing. For example, the official Unity YouTube channel has tons of tutorials as well. Those are better structured and contain correct code. From what I can see the developer in this tutorial makes a few minor mistakes. One concrete example is defining force to then not use the force. To apply force to an object you should use AddForce(...) and not apply it as velocity. This way the arrow will fly faster at the start than at the end, by letting Unity's gravity system do the work.