playMaker

Author Topic: TopDown Movement change Axis???  (Read 65 times)

Pandur

  • Junior Playmaker
  • **
  • Posts: 82
    • View Profile
TopDown Movement change Axis???
« on: September 15, 2017, 04:15:56 PM »
Hello i have a question how i can change the axis on the top down movement?

The Controlling is over WASD Keys,i use RootMotions. On the Aiming my Player look at the MouseAimPoint ( a Mesh will follow Mouse withe Mousepick Up Action).

At the moment i use a old C# Script for it here :

Code: [Select]
using UnityEngine;
using System.Collections;


public class UserInput : MonoBehaviour
{

   // public float speed = 5;
    public bool hidemouse;

    Transform camPoint;
    Vector3 camForward;
    Vector3 move;
    Vector3 moveInput;
   public float forwardAmount;
   public float turnAmount;
public GameObject CamPivot;
    Vector3 lookPos;
    Animator anim;

   


    void Start()
    {
     
   
camPoint = CamPivot.transform;

     

        if(hidemouse)
        {
            Cursor.lockState = CursorLockMode.Confined;
            Cursor.visible = false;       
        }
    }

    void Update()
    {

Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);

RaycastHit hit;

if(Physics.Raycast(ray, out hit, 100))
{
lookPos = hit.point;
}

Vector3 lookDir = lookPos - transform.position;
lookDir.y = 0;

transform.LookAt(transform.position + lookDir, Vector3.up);
    }

    void FixedUpdate()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");

        if (camPoint != null)
        {
            camForward = Vector3.Scale(camPoint.up, new Vector3(1, 0, 1)).normalized;
move = vertical * camForward + horizontal * camPoint.right;
        }
        else
        {
            move = vertical * Vector3.forward + horizontal * Vector3.right;
        }

        if (move.magnitude > 1)
            move.Normalize();

        Move(move);

        Vector3 movement = new Vector3(horizontal, 0, vertical);
     
        if (horizontal == 0 && vertical == 0)
        {

        }
       

   

       
    }

    void Move(Vector3 move)
    {
       
        if (move.magnitude > 1)
            move.Normalize();

        this.moveInput = move;
        ConvertMoveInput();


    }

    void ConvertMoveInput()
    {

        Vector3 localMove = transform.InverseTransformDirection(moveInput);

        turnAmount = localMove.x;

   
       
        if (localMove.z < -0.3f)
        {
            localMove.z = -1;
        }
        else if (localMove.z > 0.3f)
        {
            localMove.z = 1;
        }
       
        forwardAmount = localMove.z;
    }

   
            }


   
my problem is that script will not work so smoothly it will jittering some times.Thx for help :D