I haven’t written a post in over 2 months now and it felt like it was due time to reaquaint myself with Unity after a pretty long break. I’ve been doing several programming and developing courses at the same time at my school so I haven’t felt like working at Escape Plan Z during this period. Currently I’m learning some Android programming, C programming and Web development and I’m planning on making a new category on the blog for some other things I’m working on besides these games.
Onward to the game! I’ve been looking in to an issue I had last time with my gun pickup not working properly. The problem was that the gun would stick to the FPS camera at a weird vector position as seen in the picture below.
I tried to manually change the position whenever Update is called on the FPSCamera objects script by using preset offsets from the editor. This didn’t seem to work at all and the gun would simply not change and appeared to be “glued” in position. To solve this issue I created a separate game object childed to the FPSCamera and set the offsets on that object instead of the gun. Then the problem was fixed as it seems the gun prefabs position couldn’t be altered.
So this is how the structure goes:
The Player object (FPSController) has a PlayerView (FPSCamera) attached to it by default. This PlayerView represents the ingame camera which the player views the game through. Below the PlayerView I then had to create a separate game object called weapon. The gun prefab is then instantiated on the weapon object’s position which has the preset offset to the PlayerView.
Now the gun is instantiated correctly and I can move forward with other things 🙂