As with the main characters motor script I have been through two attempts to get the script up and running. The first iteration of this was a incredibly simple script that used a set of boundaries to keep the Mechanic following the player when they are moving combined with the use of the mouses position to control the mechanic once you switch to it. Bellow is a snippet of this script that demonstrates how this basic movement worked.
However this had be scrapped as firstly the boundary system that was used to make the mechanic follow the player gave unpredictable movement that appeared jittery on screen. Secondly as we have now made the decision to make the game controller compatible, the idea of using the mouse to control the mechanic became obsolete.
I then re-wrote the script and instead of using the mouse position to control movement, I recycled some of the main characters movement code to base the new system off the same key presses as main characters movement. It is also based off the same acceleration system with some slight alterations to make the movement better represent that the Mechanic is floating.
The main method that was used to achieve this affect was to incorporate a sine wave to all of the movement made by the Mechanic. This sine wave gives the appearance of floating as the Mechanic will now slightly move up and down smoothly as you move.
This code snippet shows how the sine wave was achieved:
This problem was eventually fixed by using an in-built move function that draws a line between its current and target positions and will make the rigidbody trace that line 1 point at a time. Which also allows for collisions as the rigidbody can no longer be teleported inside of an objects collider. This function combined with some tweaking of the rigidbodies settings gave the original desired movement.
Below is a snippet of code that shows how the script for this is set out.
Also the issue with the jittery movement when the Mechanic was following the player was fixed by removing the boundaries and have the mechanic constantly lerping to the position of a game object that I childed to the main character in the location that we wanted the mechanic to be.
No comments:
Post a Comment