Error with Instantiate - Object rotated incorrectly
Hello all,
I'm working on a third person shooter game with a bow and arrow, and here's a small recap of what I have.
The character has a LaserAim (LineRenderer) that's coming out of the bow, it would detect via Raycast if there's an obstacle, and would work accordingly. Now that LaserAim is pointing properly at the direction I want
However, whenever I try to instantiate an arrow, it would instantiate it at a wrong direction.
Here are my codes
For the LaserAim:
void FixedUpdate () {
// initialize position, direction, and initial position for the LineRenderer/LaserAim
init_pos = this.transform.position;
laser_direction = character.transform.TransformDirection (Vector3.forward);
laser_line.SetPosition (0, init_pos);
if (Physics.Raycast (init_pos, laser_direction, out target_hit, laser_range)) {
// if Raycast detects an object after a certain range, fix the position for the LineRenderer
laser_line.SetPosition (1, target_hit.point);
} else {
// else, would go to the extreme point of the range
end_pos = init_pos + laser_direction * laser_range;
laser_line.SetPosition (1, end_pos);
}
}
For the Arrow Instantiate:
void Update () {
// shoot arrow
if (character_animation.GetBool ("ArrowFlying")) {
GameObject cloneArrow = (GameObject)Instantiate (arrow, init_pos, Quaternion.identity);
cloneArrow.transform.position = init_pos;
cloneArrow.transform.rotation = character.transform.rotation;
character_animation.SetBool ("ArrowFlying", false);
}
}
Does anyone have any idea what I'm doing wrong, or how I can fix it?
Your answer
![](https://koobas.hobune.stream/wayback/20220612164056im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check rotation of an obstacle 0 Answers
Gun-recoil problem C# 0 Answers
Undesired Angles with transform.Rotate(...) 0 Answers
Applying a rotation relative to the object's starting rotation 0 Answers
Rotation Issue 0 Answers