- Home /
Question by
valekpeter7 · Jan 29, 2020 at 03:51 PM ·
movementmobilenavmeshjoystick
Player movement with joystick + Automove NavMesh
Hello everyone,
I need to move player with my joystick and also with automove by clicking on NavMesh. Both of these process are working for me but only separately.
I need them to work at the same time
Thank you for your help !
My Code for Automesh move by clicking on ground:
public void MoveToPoint (Vector3 point)
{
agent.SetDestination(point);
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
Debug.Log("We hit " + hit.collider.name + " " + hit.point);
// Move player
motor.MoveToPoint(hit.point);
//Stop focus object
}
}
}
My code for Joystick move:
Vector3 move = new Vector3(joystick.Horizontal * 10f, 0, joystick.Vertical * 10f);
_controller.Move(move * Time.deltaTime * Speed);
if (move != Vector3.zero)
transform.forward = move;
_velocity.y += Gravity * Time.deltaTime;
_velocity.x /= 1 + Drag.x * Time.deltaTime;
_velocity.y /= 1 + Drag.y * Time.deltaTime;
_velocity.z /= 1 + Drag.z * Time.deltaTime;
_controller.Move(_velocity * Time.deltaTime);
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612222330im_/https://answers.unity.com/themes/thub/images/avi.jpg)