Joystick controlled object should move locally
I have an object that is controlled by a virtual joystick, when the controlled object is rotated, the "front" should no longer be the global but the local "front", so that when it is rotated, it moves down when the forward button is pressed. How do I get there?
I'm useing this https://assetstore.unity.com/packages/tools/input-management/joystick-pack-107631 joystick asset.
This Code is used to send data from joystick to object.
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class MyMovement : MonoBehaviour
{
protected Joystick joystick;
public float speed = 25f;
// Start is called before the first frame update
void Start()
{
joystick = FindObjectOfType<Joystick>();
}
// Update is called once per frame
void Update()
{
var rigidbody = GetComponent<Rigidbody>();
rigidbody.velocity = new Vector3(joystick.Horizontal * speed, rigidbody.velocity.y, joystick.Vertical * speed);
}
}
Your answer
Follow this Question
Related Questions
How can i make my player look at the same direction where its moving? [JOYSTICK ANDROID] 0 Answers
how to set joystick to follow camera's position? 0 Answers
C# 3D Collider Without Fixed Points or use Mesh Filter Instead? 0 Answers
How to implement the ability to move and place objects in HoloLens Application? 0 Answers
Rotation on moving using virtual joystick is not working as expected in 3D game. 0 Answers