Answer the question
In order to leave comments, you need to log in
Rotation control with joystick, how?
Hello! Straight to the point. I have a dragon and with the help of a joystick I "drag" it around the scene, but since it is a 3d model and it has a face, it turns out that it moves sideways. I want him to go wherever he goes and turn around. And so that when you release the joystick, the object stops moving. Here is the code for the movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JoystickPlayerExample : MonoBehaviour
{
public float speed;
public VariableJoystick variableJoystick;
public Rigidbody rb;
//gameObject.transform.Rotate(0, 100 * Time.deltaTime ,0);
public void FixedUpdate()
{
Vector3 direction = Vector3.forward * variableJoystick.Vertical + Vector3.right * variableJoystick.Horizontal;
rb.AddForce(direction * speed * Time.fixedDeltaTime, ForceMode.VelocityChange);
}
}
Answer the question
In order to leave comments, you need to log in
Well, what's the problem?
There is direction and there is .transform.Rotate - it remains to tie it together.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question