- Home /
What's the correct input for character movement
The project im working is mobile game but for test and presentation we need to use PC input to make it easier ,currently the movement using mobile joystick are inverted and off from the camera.For the camera I am using the CineMachine to create 3rd perspective camera the only problem is the character movement input and animations. Here the code below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerController : MonoBehaviour
{
public float speedMove;
public float jumpPower;
private float gravityForce;
private Vector3 moveVector;
private CharacterController ch_controller;
private Animator ch_animator;
private void Start()
{
ch_controller = GetComponent<CharacterController>();
ch_animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
CharacterMove();
GamingGravity();
}
private void CharacterMove()
{
ch_animator.ResetTrigger("Jump");
ch_animator.SetBool("Falling", false);
moveVector = Vector3.zero;
//moveVector.x = Input.GetAxis("Horizontal") * speedMove;
moveVector.z = CrossPlatformInputManager.GetAxis("Vertical") * speedMove;
moveVector.x = CrossPlatformInputManager.GetAxis("Horizontal") * speedMove;
if (moveVector.z != 0 || moveVector.x != 0)
ch_animator.SetBool("Move", true);
else ch_animator.SetBool("Move", false);
if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) == 0)
{
Vector3 direct = Vector3.RotateTowards(transform.forward, moveVector, speedMove, 0.0f);
transform.rotation = Quaternion.LookRotation(direct);
}
{
if (gravityForce < -3f) ch_animator.SetBool("Falling", true);
}
moveVector.y = gravityForce;
ch_controller.Move(moveVector * Time.deltaTime);
}
private void GamingGravity()
{
if (!ch_controller.isGrounded)
gravityForce -= 20f * Time.deltaTime;
else
gravityForce = -1f;
if (CrossPlatformInputManager.GetButton("Jump") && ch_controller.isGrounded)
{
gravityForce = jumpPower;
ch_animator.SetTrigger("Jump");
}
}
}
I want to help you, but I'm not sure I understand the question.
You want the input to not be inverted? If so you can just flip a few variables, or even create an isInverted bool and use it to manipulate said variables.
What do you mean by movement is off from the camera?
And what's the problem with the animations?
Hi do you have other social media platform such as $$anonymous$$icrosoft $$anonymous$$m or Discord? I will show u the project is , from my $$anonymous$$m mate perspective is the player should have connection with the camera and runs forward to the position the camera is running.
Just share your screenshots and information here, that's what this platform is for.
You can edit your original post and add to it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234538im_/https://answers.unity.com/themes/thub/images/avi.jpg)