Tutorial 2 - KIT207
Above is the end result of what has been animated. The player is fully controllable using WASD and CTRL for running but no jump :(
To start off, I imported the character above from the Simple People pack by Synty and added the CharacterController component, then using the premade animations already part of the pack Simple People pack, I made my own animation controller, Added it to the character onto the Animator component. Inside the animation controller. I added two conditional booleans called Forward and IsRunning shown below.
Then after that. I added 3 animation states called Idling, Walk_Static and Run_Static and set all transitions to have no exit time.
After that, I just created a script called PlayerController and added it onto the character and wrote this script...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float TurnSpeed = 2.0f;
public float WalkSpeed = 2.0f;
public float RunSpeedMultiplier = 2.0f;
private Animator animator;
private CharacterController cc;
private float ZSpeed, XSpeed
// Start is called before the first frame update
void Start()
{
animator = GetComponent<animator>();
cc = GetComponent<charactercontroller>();
}
void Update()
{
var walkSpeed = WalkSpeed;
ZSpeed = Input.GetAxis("Vertical");
XSpeed = Input.GetAxis("Horizontal") transform.Rotate(0, XSpeed * TurnSpeed * Time.deltaTime, 0);
if (Input.GetAxis("Fire1") > 0.0f) walkSpeed *= RunSpeedMultiplier;
cc.Move(transform.forward * walkSpeed * ZSpeed * Time.deltaTime);
animator.SetBool("Forward", ZSpeed >= 0.2f);
animator.SetBool("IsRunning", Input.GetAxis("Fire1") > 0.0f);
}
}
Simple People Synty Studios - Simple People - Cartoon Characters | 3D Humanoids | Unity Asset Store
KIT207 Portfolio
Status | Released |
Category | Other |
Author | SineVector241 |
More posts
- Lighting, ShaderGraph and Tutorial 5 - KIT207Apr 16, 2024
- Game Ideas - KIT207Apr 07, 2024
- Simple Game - KIT207Apr 07, 2024
- Tutorial 3 - KIT207Mar 28, 2024
- Terrain + ProBuilder - KIT207Mar 21, 2024
- Animation - KIT207Mar 17, 2024
- Tutorial 1 - KIT207Mar 15, 2024
- Blender Model - KIT207Mar 07, 2024
Leave a comment
Log in with itch.io to leave a comment.