Sunday 27 April 2014

Re-programming the player ship

This will be quite a short blog post, due to the nature of it. I have had several problems in the part with my player code scripts and I have finally worked out what went wrong with it and have fixed it.

I was meant to start doing work on the planet sizes and the level design, but this has taken priority today since I have noticed it and want to fix it before it becomes a major problem. I after posting this blog I will continue with the rest of the game.

The problem:

When I would make an object look at the player, e.g. the mining particle system that fires towards the player, it would either not fire or it would fire in a completely different direction to the player. Other items would so this as well on occasion.

The explanation:

The player ship is composed of several different game objects, each one with a different purpose. There is an empty "gameObject" that holds everything, the player mesh, a green particle system, and several particle systems and point lights on the exhausts to add the immersion to make it a little more believable.

Originally I added the movement script to the mesh and the rigid body to it as well. When the game was running, only the mesh would move inside of the empty parent game object. With this in mind, it explained why some of the transforms were strange and because the parent was in the position it started at the beginning of the scene and the look at for some particle systems would either not work, or fire towards the stationary parent game object.

This is a major design floor I have managed to spot before it's too late. When I last redesigned and re-created the player Prefab, it made sense to have a game object to hold everything because for example, if I needed to change the position because some of the other game object that were children of the mesh would operate correctly. Thus I made everything equal in the hierarchy. However I did not think to mode the move the player scrip to the parent game object.

How I have fixed the error:

Basically I have removed the script from the player ship mesh, and any mouse turning scripts from the mesh and have added them to the parent game object and added the current values in the inspector and the same for the audio sources. In the coming weeks this will make my life a lot easier. I wish I had discovered this sooner. When I did this today I had to reassign some variables in the inspector for the trader ship the activate certain sounds, but apart for that, everything is fine. This should hopefully avoid any future problems involving "Transforms".

No comments:

Post a Comment