Labels

Monday 25 November 2013

Character Movement Updates

Since the previous post on the Unity demo scene, much has been changed to the main characters motor script as during the presentation of our demo scene we found the controls to be too unresponsive and "clunky" causing the level to become much harder to navigate.

Originally the main characters character controller was driven by an axis based system, which was used as the key presses would return an emulated analogue value between 1 and -1. What this effectively means is that when a key was pressed instead of simply acting as a switch and toggling between on and off, when you pressed a key down the returned value would interpolate between 0 and its respective value, 1 for right and -1 for left. 

This decision was originally made for two reasons, the first being that it made scripting the direction change initially easier, as the positive and negative values correspond directly to the direction in which the character needs to move. This allowed me to simply multiply the returned key press value by a set speed to allow the character in the desired direction. This at the time seemed to be much easier than the alternative, which was to use the key presses to then figure out what direction the character should move in and then with that data multiply the move speed by either a positive or a negative number to correspond with the chosen direction.

The second of these reasons being that if we used a controller with an analogue stick to play the game, the player would have more control over the main characters speed, as they could stick to a certain position with the analogue stick limiting the main characters maximum speed.

However during last week this system was scrapped. This was due to the fact that the interpolation of the keys returned value was handled internally by unity which meant that I lost a large amount of control over the values fed into the movement scripts. Which was preventing me from being able to properly integrate a good momentum and inertia based movement system.

I re-wrote the scripts based of the keys acting as switches and created my own acceleration system, that to some extent replicated some of the same effects that was achieved by the axis based system, but this allowed me full control of the values being used to drive the movement script. As I had full control of these values I was able to create a much smoother and complex movement system.


This is a comparison of the two systems being used with just basic movement:


The above is the old system based on the interpolated axis values of the key presses.

This is the updated script with the new system implemented.


Once the basic movement had been finished to a good standard using code snippets that I edited from Unity's default character motor script I was also able to implement support for sliding down steep slopes.

Other features that I have so far been able to implement include:

  • When the character hits an object while moving while in the air they will slow down accordingly.
  • When the character hits an object above them while jumping they are pushed back down with a force that is equal to the force they hit the object with.
  • Jumping is time based, you only jump when the button is pressed down however there is a 0.2 second allowance for human error, so it is possible to jump if you press the button less than 0.2 seconds before you are actually grounded.
  • The motor script supports moving platforms, allowing the character to move along with any platform that may move.
Now that these features have been implemented all that leaves to be done to the character motor script is to bug test it further and eventually attempt to incorporate a system that allows for wall jumping to be achieved.

No comments:

Post a Comment