Skip to content

Instantly share code, notes, and snippets.

@ditzel
Last active July 8, 2023 08:42
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ditzel/3933efad282d739b5827cf1928fdcfb6 to your computer and use it in GitHub Desktop.
Save ditzel/3933efad282d739b5827cf1928fdcfb6 to your computer and use it in GitHub Desktop.
Touch Third Person Character Controller in Unity: https://youtu.be/8ycgJbQegAo
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
public class ThirdPersonInput : MonoBehaviour
{
public FixedJoystick LeftJoystick;
public FixedButton Button;
public FixedTouchField TouchField;
protected ThirdPersonUserControl Control;
protected float CameraAngle;
protected float CameraAngleSpeed = 0.2f;
// Use this for initialization
void Start()
{
Control = GetComponent<ThirdPersonUserControl>();
}
// Update is called once per frame
void Update()
{
Control.m_Jump = Button.Pressed;
Control.Hinput = LeftJoystick.inputVector.x;
Control.Vinput = LeftJoystick.inputVector.y;
CameraAngle += TouchField.TouchDist.x * CameraAngleSpeed;
Camera.main.transform.position = transform.position + Quaternion.AngleAxis(CameraAngle, Vector3.up) * new Vector3(0, 3, 4);
Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 2f - Camera.main.transform.position, Vector3.up);
}
}
@An3Dev
Copy link

An3Dev commented Jun 25, 2018

ThirdPersonInput is misspelled.

@drashti99
Copy link

inputvector for left joystick isnt getting recognised

@mdmishanurkhan
Copy link

inputvector for left joystick isnt getting recognised

Yes, I am also facing this problem

@ZacPetty
Copy link

ZacPetty commented Apr 25, 2020

The name in the joystick file was changed to just input, I had trouble finding it. Look around line 41 in the joystick file.

@IraFaisal
Copy link

inputvector for left joystick isnt getting recognised

yes exactly i am also facing this problem when u go to this script u will see there is nothing inside it

@adino-maxxin
Copy link

Do it like this. Control.Hinput = LeftJoystick.Horizontal; not inputVector.x Control.Vinput = LeftJoystick.Vertical; not inputVector.y. Bcos d input is locked in d script.

@Laptop808
Copy link

NullReferenceException: Object reference not set to an instance of an object. thirdpersoninput.Update () (at Assets/thirdpersoninput.cs:30). Problem at the line of:
CameraAngle += TouchField.TouchDist.x * CameraAngleSpeed;

    Camera.main.transform.position = transform.position + Quaternion.AngleAxis(CameraAngle, Vector3.up) * new Vector3(0, 3, 4);
    Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 2f - Camera.main.transform.position, Vector3.up);

The touch field has no reponse when play and how to fix this?

@adino-maxxin
Copy link

adino-maxxin commented Dec 28, 2020 via email

@rrfunner
Copy link

FixedJoystick and FixedButton script are deleted , please available that script ,
I can't use your asset

@AbdurRehmanBajwa
Copy link

Assets\Scripts\ThirdPersonInput.cs(28,39): error CS1061: 'FixedJoystick' does not contain a definition for 'inputVector' and no accessible extension method 'inputVector' accepting a first argument of type 'FixedJoystick' could be found (are you missing a using directive or an assembly reference?)

: (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment