Ray does not rotate with gameobject when IK is enabled
I am working on a third person shooter. The gun the player's character holds has a BulletSpawnPoint object that is a child of the gun object and place directly in front of the gun, that object determines the position and direction of the bullet's raycast. However, when I have IK enabled on the character's right arm, the position and direction of the bullet's ray does not change even when the BulletSpawnPoint moves with the weapon. Here's the video demostrating the problem: https://youtu.be/ixq0gkzGl54
The while line on the video is the result from the following code: Debug.DrawRay (bulletSpawnPoint.transform.position, bulletSpawnPoint.transform.forward*100, Color.white);
The position and forward of the BulletSpawnPoint object change yet the ray does not move! For some reason this only occurs when the IK on the player character's right arm (the one holding the gun) is enabled. If IK is disabled the ray moves as it should.
How can I fix this issue?
Answer by ale-carrazzoni · Jan 14, 2016 at 02:50 AM
It turns out that the position of the bulletSpawnPoint when IK is enabled is updated on FixedUpdate. So moving the code to FixedUpdate or LateUpdate fixes the problem.
Your answer
Follow this Question
Related Questions
mimicking movement of one object to another with different scale/location. 1 Answer
transform.localPosition += transform.forward moves object toward (0, 0, 0) 2 Answers
Move GameObject with transform.position 1 Answer
Create a 2D array (3 columns, 1000 rows)? 1 Answer
How can I create movement like a bull? (Enemy run towards player) 0 Answers