- Home /
UI Direction arrow from 3d object.
Hello All I have a 3d Game Object called Wind Manager with a wind manager script. Using a vector3.forward i get the direction of the wind. What im trying to do is make a 2d arrow pointing in the direction of the wind compared to my player. below is what i have so far but it kinda gets stuck then switched directions. Any help would be greatly appreciated.
using Crest;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WindManager : MonoBehaviour
{
[SerializeField] Transform boat;
[SerializeField] float windAngle;
[SerializeField] ShapeGerstnerBatched waves;
[SerializeField] public Image windArrow;
[SerializeField] Vector3 direction;
public static WindManager instance;
// Start is called before the first frame update
void Awake()
{
if(instance == null)
{
instance = this;
}
}
// Update is called once per frame
void Update()
{
direction = transform.forward;
Vector3 windRotation = WindManager.instance.windArrow.transform.eulerAngles;
windRotation.z = Vector3.Angle(boat.forward, WindManager.instance.GetWindDirection());
WindManager.instance.windArrow.transform.eulerAngles = windRotation;
waves._windDirectionAngle = -transform.eulerAngles.y;
//Vector3 forward = transform.TransformDirection(Vector3.forward) * 1000;
//Debug.DrawRay(transform.position, forward, Color.green);
}
public Vector3 GetWindDirection()
{
return direction;
}
}
It's really not clear what you want to do exactly. So you have a Vector3; the wind direction, and you want to convert it to a Vector2 relative to the player? So basically project the wind direction on the players ground plane?
I want to make an arrow on the UI showing the wind direction. That will adjust accordingly. But if you go to far left the arrow just sort of snaps to the opposite direction.