- Home /
Question by
balajikrishnan · Feb 12, 2020 at 12:35 PM ·
c#unity 3.5
unity character move inverse rotation joystick
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Playermovement : MonoBehaviour {
public FixedTouchField touchField;
public FixedJoystick leftjoystick;
protected CharacterController characterController;
Vector3 Movedir = Vector3.zero;
public Rigidbody rb;
protected Animator animator;
protected float cameraangleY = 2f;
protected float cameraanglespeed = 2f;
protected float camerayposY;
protected float cameraposspeed = 2f;
public FixedJoystick rightjoystick;
public float rot;
public float rotspeed = 80f;
void Start()
{
rb = GetComponent<Rigidbody>();
characterController = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
void Update()
{
rb.velocity = new Vector3(leftjoystick.Horizontal * 1f, 0, leftjoystick.Vertical * 1f);
if (leftjoystick.Horizontal != 0f || leftjoystick.Vertical != 0f)
{
animator.SetInteger("conditions", 1);
transform.rotation = Quaternion.LookRotation(rb.velocity);
}
else
{
animator.SetInteger("conditions", 0);
}
transform.rotation = Quaternion.AngleAxis(cameraangleY, Vector3.up);
cameraangleY += rightjoystick.Horizontal * cameraanglespeed ;
Camera.main.transform.position = transform.position + Quaternion.AngleAxis(cameraangleY, Vector3.up) * new Vector3(0, 3, -4);
Camera.main.transform.rotation = Quaternion.LookRotation(transform.position + Vector3.up * 2f - Camera.main.transform.position, Vector3.up);
}
}
Comment