- Home /
Joystick controller problem walking on sphere
Hi guys, I'm developing a game for a university project. I found a problem with the rotation of the character walking on a sphere, when I start the game and I'm in the upper part of the world everything works correctly, but when I move elsewhere the joystick remains unchanged and consequently the vector of the movement is incorrect. I also leave you the link of the problem to better understand and the code.
https://www.youtube.com/watch?v=O5i2iKR3YGs
Thanks in advance.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class TouchController2 : MonoBehaviour
 {
     public Joystick ljoystick;
     public Transform astronauta;
     public float velocity = 5;
     private Vector3 vettoreMovimento;
     private Vector3 forwardIniziale;
     public float rotaspeed = 5f;
     // Start is called before the first frame update
     void Start()
     {
         if(astronauta == null)
             astronauta = GameObject.FindGameObjectWithTag("Player").transform;
         forwardIniziale = astronauta.forward;
     }
 
     // Update is called once per frame
     void Update()
     {
 
         vettoreMovimento = new Vector3(ljoystick.Horizontal, 0f, ljoystick.Vertical);
         float angle = Vector3.SignedAngle(astronauta.forward, vettoreMovimento, this.transform.up);
 
         Debug.DrawRay(this.transform.position, astronauta.forward, Color.red);
         Debug.DrawRay(this.transform.position, vettoreMovimento , Color.blue);
         //Debug.DrawRay(this.transform.position, vettoreMovimento, Color.red, 0.5f);
         //astronauta.up = this.transform.up;
         //astronauta.rotation = Quaternion.LookRotation(vettoreMovimento, this.transform.up);
         this.transform.Translate(vettoreMovimento * velocity * Time.deltaTime);
 
         if (ljoystick.Horizontal != 0 && ljoystick.Vertical != 0)
         {
             astronauta.Rotate(new Vector3(0f, angle, 0f) * Time.deltaTime * rotaspeed, Space.Self);
         }
 
     }
 
     
 }
 
Answer by MatteoZocca · Apr 05, 2020 at 08:25 PM
Solved with this:
 transform.TransformDirection(movementVector);
Your answer
 
 
             Follow this Question
Related Questions
No movement to negative z-axis. 1 Answer
Joystick problem (i only want horizontal movement) 0 Answers
Moving an ob around a sphere 1 Answer
Joystick for WASD & Joystick for Camera? 0 Answers
Rotate and move character with Joystick 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                