Witam.
Wpadłem na pomysł zrobienia jakiejś gry gdzie lata się statkiem (w poprzednim pytaniu też był z nim problem) i coś tam się zbiera albo się walczy. Na razie chciałem zrobić sterowanie. Steruje się klawiszami wsad a statek obraca się tam gdzie lecimy. I tu jest problem z tym odwracaniem. Niby jakoś się obraca ale strasznie nienaturalnie i czasem przodem a czasem tyłem. Oto kod:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControls : MonoBehaviour {
public float mSpeed = 5;
public GameObject spaceship;
float spdx;
float spdz;
float angle;
Vector2 speed = new Vector2(0f, 0f);
Vector2 zero = new Vector2(0f, 1f);
void Start () {
}
void Update () {
speed = new Vector2(spdx, spdz);
if (spdx != 0 && spdz != 0)
{
angle = Vector2.Angle(speed, zero);
}
spdx *= 0.98f;
spdz *= 0.98f;
if (Input.GetKey("w"))
{
spdz += mSpeed;
}
if (Input.GetKey("s"))
{
spdz -= mSpeed;
}
if (Input.GetKey("a"))
{
spdx -= mSpeed;
}
if (Input.GetKey("d"))
{
spdx += mSpeed;
}
transform.Translate(spdx * Time.deltaTime, 0f, spdz * Time.deltaTime);
spaceship.transform.rotation = Quaternion.Euler(90f, angle-90f, 0f);
print(angle);
}
}
Kod jest dodany do grupy objektów "Player" do której należą kamera i statek.
Proszę o pomoc z tym obracaniem.