- Home /
Question by
unity_qoQ18Wrsw3J_Qg · Jul 30, 2020 at 07:09 PM ·
rotationquaternionorbit
i don't get why the object around the player is not rotating.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotatewithplayer : MonoBehaviour
{
Vector3 v;
public float a;
public Transform player;
// Start is called before the first frame update
void Start()
{
v = new Vector3(player.position.x - transform.position.x, 0, player.position.z - transform.position.z);
}
// Update is called once per frame
void Update()
{
if ((transform.position.y == player.position.y + 10)& Input.GetKey("d"))
{
v = Quaternion.AngleAxis(a * Time.deltaTime, new Vector3(0, 1, 0)) * v;
transform.position = player.position +v ;
}
if ((transform.position.y == player.position.y + 10) & Input.GetKey("q"))
{
v = Quaternion.AngleAxis(-a * Time.deltaTime, new Vector3(0, 1, 0)) * v;
transform.position=player.position+ v + new Vector3(0,10,0);
}
}
}
Comment
Your answer
