CHARACTER SCRIPTS
Overview
There are 3 scripts attached to the character object.
Pixel Character
Storing object reference inside the character object and character customization.
Pixel Character Controller
Controlling movement of the character.
Pixel Character Input Mouse and Keyboard
Reading mouse and keyboard input and feed into the Pixel Character Controller script
There are also 2 scripts attached to the Animator
object inside character. Generally, you don’t need to pay attention to these two scripts.
Animation Event Receiver
For receiving animation events.
Root Motion Receiver
For receiving root motion from the animation.
Pixel Character
For storing object reference inside the character object and character customization.
Reference Foldout
Contains reference to objects inside the character object.
Customization Foldout
Parameters here is mainly for tweaking the character appearance. The customization is mainly done by changing the materials here. Can be changed both in editor and runtime.
Blink Interval
The interval range for the character to play an eye blink animation.
Hat Material
Material of the character’s hat
Hair Material
Material of the character’s hair
Eye Material
Material of the character’s eye
Eye Base Material
Material of the character’s eye shape.
You only need to change this when changing the character’s gender.
Facewear Material
Material of the character’s facewear.
Cloth Material
Material of the character’s cloth.
Pants Material
Material of the character’s pants.
Socks Material
Material of the character’s socks.
Shoes Material
Material of the character’s shoes.
This will be displayed behind the character’s pants.
Back Material
Material of the object the character carries on the back.
Body Material
Material of the character’s body.
You need to change this when changing the character’s gender.
Also, special character presets would use their specific body material, like Vampire or Zombie.
Clip Hair
Hide part of the character’s hair.
When wearing curtain hats, you need to enable this.
Hide Hair
Completely hide the character’s hair.
Shoes in Front
Whether to display shoes in front of the character’s pants.
Runtime Foldout
Parameters here should only be changed at runtime except Facing
.
Facing
The character’s facing.
Can be changed in editor to set the character’s initial facing.
Alpha
Controls the transparency of the entire character.
Is Dead
Whether the character is dead.
Turning this on will only make the character appear dead on the graphic side. For making the character truly dead, turn on the Is Dead
on the Pixel Character Controller
script.
Expression
The character’s expression.
Injured Front
Play Injured Front
animation.
Injured Back
Play Injured Back
animation.
Detach Weapon
Detach weapon to a separated object from the character.
Returns the detached weapon game object.
Clear Weapon
Clear out everything in the weapon slot.
Pixel Character Controller
Script for controlling the character’s movement.
It will modify some of the Facing
parameters in the Pixel Character
script and parameters in the Animator
to control animation.
Movement Foldout
Parameters for the character’s movement.
Ground Check Layer Mask
Objects under this layer mask will be consider ground the character can stand on.
Walks Speed Max
Max walking speed.
Walks Acc
Walking Acceleration.
Run Speed Max
Max running speed.
Run Acc
Running Acceleration.
Crouch Speed Max
Max move speed while crouching.
Crouch Acc
Crouching acceleration.
Crawl Speed Max
Max move speed while crawling.
Crawl Acc
Crawling acceleration.
Air Speed Max
Max move speed while in air
Air Acc
Air acceleration
Ground Drag
Braking acceleration (from movement to still) while on ground
Air Drag
Braking acceleration (from movement to still) while in air
Jump Enabled
Whether the character can jump.
Jump Speed
Speed applied to the character when jump.
Jump Cooldown
Time needed to be able to jump again after landing.
Jump Tolerance
When character is off ground and inside this time, the character is still able to jump.
Jump Gravity Multiplier
Gravity multiplier when character is jumping.
Should be within [0.0,1.0]
, set it to lower value so that the longer you press the jump button, the higher the character can jump.
Fall Gravity Multiplier
Gravity multiplier when character is falling.
Should be equal or greater than 1.0
Dash Enabled
Whether the character can dash.
Dash Speed Start
Speed when dash starts.
Dash Speed Max
Max move speed while dashing.
Dash Acc
Dash acceleration.
Dash Time
Time the dash state will last.
Dash Cooldown
Time it takes for the character to be able to dash again after exiting dash state.
Dodge Enabled
Whether the character can dodge.
Dodge Speed Mul
Dodge speed multiplier
Dodge Cooldown
Time it takes for the character to be able to dodge again after exiting dodge state.
Ladder Climb Enabled
Whether the character can climb ladder.
Ladder Climb Speed
Ladder climbing speed.
Ladder Climb Speed Fast
Ladder climbing speed when the run key (by default is SHIFT) is pressed.
Ledge Climb Enabled
Whether the character can climb ledge.
Attack Foldout
Parameters for the character’s attack action.
Attack Action
Attack action to perform whether primary attack key (by default is LMB) is pressed.
Attack Action Melee
Attack action to perform whether melee attack key (by default is V) is pressed, or when the character is in a state when primary attack action is not available, like when crawling or climbing ladder.
Attack Speed Mul
Speed multiplier of the attack animation.
You can use this to make the character attack quicker or slower. Default value is 1.0
Attack Cooldown
Time needed to be able to attack again after last attack action ended.
Default value is 0.0
, means no cooldown.
Throw Force
When using Throw
attack action, the character will throw out the weapon it is holding.
This defines the force applied to the thrown weapon.
Throw Angular Speed
The angular speed applied to the thrown weapon.
Projectile Speed
The speed applied the projectile when using Cast
or Archery
attack action.
Projectile Prefab
The prefab of the projectile to be instantiate when using Cast
or Archery
attack action.
Event Foldout
This foldout contains some Unity events that you can use to trigger your own function.
A typical use case is to play sound effects when curtain event happens.
On Footstep
When the character’s foot touches the ground in animation like walk or run.
On Jump
When the character jump away from ground.
On Land
When the character land on the ground from air.
On Dodge Start
When dodge action starts.
On Dodge End
When dodge action ends.
On Attack Start
When attack action starts.
On Attack Hit
When attack action is supposed to hit the target. Damage to the target can be applied at this event.
On Attack End
When attack action ends
On Bow Pull
When using Archery
attack action, the character start pulling the bow string.
On Bow Shoot
When using Archery
attack action, the character release the bow string and the arrow is shot.
On Throw
When using Throw
attack action, the character throws out the holding weapon.
Input Foldout
Parameters for receiving inputs from input scripts.
If you are going to use your own input scripts, you need to modify these parameters in your scripts.
Only available at runtime.
Input Move
movement input, x for horizontal, y for vertical, x and y should be in [-1.0, 1.0]
Input Run
Run input, when enabled the character will run instead of walk.
Input Dash
Dash input, when triggered the character will enter dash state.
Input Dodge
Dodge input, when triggered the character will enter dodge state.
Input Crouch
Crouch input, when enabled the character will be crouching.
Input Crawl
Crawl input, when enabled the character will be crawling. Will override crouch input.
Input jump
Jump input, when triggered the character will start to jump.
When continuously enabled the character will jump higher.
Input Attack
Primary attack input, will trigger the attack action when available.
Input Melee
Melee attack input, will trigger the melee attack action.
Input Look
Look input, when enabled the character will look at the position defined by Input Target
Input Target
This is a world space Vector2
position that defines the target the character should look at or point at when performing curtain attack action.
Debug Foldout
Parameters for switching debug gizmos display.
Runtime Foldout
Parameters here should only be changed at runtime.
Most parameters here is read only and just for exposing states of the controller.
Pixel Character Input Mouse and Keyboard
This script will read mouse and keyboard input and modify parameters in the Input
foldout of the Pixel Character Controller
script.
If you are going to use your own input script or let an AI to control the character, just remove this script.
It is also a good example for showing how to feed input to the Pixel Character Controller
script.
Is Dead
Is the character dead? if yes, plays dead animation and disable control.
Last updated