Search Unity

Third person movement

Discussion in 'Editor & General Support' started by bash_the_coder, Jul 7, 2020.

  1. bash_the_coder

    bash_the_coder

    Joined:
    May 31, 2020
    Posts:
    15
    Hi there,

    I'm currently make a third person multiplayer game in unity, and i'm kind of struggling to get nice third person movement
    and i have tried everything but just didn't fell right, or work right. So if anyone could maybe help me with some idea's of what i could do or check out. And also this doesn't really feel right for me only because i'm also trying to and in some animations.
     
  2. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    First, you have to be more specific about what's not "feeling or working right".

    Second, off the top of my head, you need a character controller and a following camera. There are tons of premade free assets in the Asset store for this and YouTube tutorials. It sounds like you're a beginner so you should go through some of the Unity Learn content that's now free to ensure you have a grasp on the engine and workflow first.
     
    bash_the_coder likes this.
  3. bash_the_coder

    bash_the_coder

    Joined:
    May 31, 2020
    Posts:
    15
    Okay, thank you DrodifyDevs, will try and find some permade assets on the asset store and see what I find. And also for the camera follow I have gotten that to work right so the only thing i'm trying to get around is the player movement :)
     
  4. bash_the_coder

    bash_the_coder

    Joined:
    May 31, 2020
    Posts:
    15
    Oh, and also what i meant about it not feeling right was that , when ever you would move forward and stop it would like loop for a extra 4 sec. And if the character was not on a surface the character controller would just carry it over, even though there was no where to step. I have fixed it a couple times but now it seem's that it's not going away:(
     
  5. bash_the_coder

    bash_the_coder

    Joined:
    May 31, 2020
    Posts:
    15
    Btw i'm using unity version 2019.4
     
  6. bash_the_coder

    bash_the_coder

    Joined:
    May 31, 2020
    Posts:
    15
    Hi there,

    I've found a good tutorial on third person movement but i'm getting a error saying, Vector2 does not contain a definition for 'GetKey'. Here is the code


    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float walkSpeed = 2;
    public float runSpeed = 6;

    Animator animator;

    void Start() {
    animator = GetComponent<Animator>();
    }

    void Update() {

    Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw( "Vertical"));
    Vector2 inputDir = input.normalized;

    if(inputDir != Vector2.zero){
    transform.eulerAngles = Vector3.up * Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg;
    }

    bool running = input.GetKey(KeyCode.LeftShift);
    float speed = ((running) ? runSpeed : walkSpeed) * *inputDir.magnitude;

    transform.Translate(transform.forward * speed * Time.deltaTime, Space.World);

    float animationSpeedPercent = ((running) ? 1 : .5) * inputDir.magnitude;
    animator.SetFloat("SpeedPercent", animationSpeedPercent);
    }
    }