Rotation script isn't working
Its a simple script I dont know where I'm going wrong I should know better
I'm trying to match one objects rotation with another. The script retrieves the rotation of the ship, which I have specified in the inspector and applies it to the object the script is applied to. No matter what I try, Ballrot always returns (0,0,0) no matter the rotation of the ship.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HorizonScript : MonoBehaviour
{
private Quaternion BallRot;
public Transform ParentShip;
private void HorizonRot()
{
ParentShip = GetComponent<Transform>();
BallRot = ParentShip.transform.rotation;
Debug.Log(BallRot);
this.transform.rotation = BallRot;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
HorizonRot();
}
}
im stumped cheers
Answer by dan_wipf · Mar 29, 2019 at 06:09 PM
well, you acually pass the transform’s rotation to its transform rotation.. if you want to use the parents rotation simply use this code:
transform.rotation = transform.parent.rotation;
The Parent ship isn't actually a parent of the ball, the ball is separate and is projected onto the UI cheers
well you override the transform you’ve selected in the inspector. so decide which way you want to go..
A; don’t call getcomponent, which is anyway unecessary just use transform and select the transform parentShip in inspector
B: dont make parentShip public and find the component in the start method => for example
parentShip = transform.Find(“NameOfTransform”);
if it’s correct answered please accecpt the answer as right ;)
Your answer
Follow this Question
Related Questions
Quaternion snaps back to original position 2 Answers
Getting a 2D object to face the direction of its velocity relative to other objects in the level 0 Answers
AI targeting player in complete wrong direction 1 Answer
How do I smoothly rotate the GameObejcts with negative 90 degrees 0 Answers
How do I rotate the GameObejcts smoothly with negative degrees 0 Answers