- Home /
transform.SetPositionAndRotation(0, 0, 0),SetPositionAndRotaion
I am a beginner and need help with this! transform.SetPositionAndRotation( //what do i put in here! )
Unity's answer did not make sense!,I am a beginner and I need help with this line of code here (need it for my game!). transform.SetPositionAndRotation( // do not know what to do in here! )
Answer by dan_wipf · Nov 18, 2018 at 07:45 AM
ok first it's a short form of those two properties:
transform.position (Vector3, representative for 3d Vectors and Points)
transform.rotation (Quaternion, representative for Rotations in 3d Spaces )
what you can put in transform.SetPositionAndRotation is following for example:
using UnityEngine;
public class ExampleScript : MonoBehaviour {
public Vector3 MyPosition;
public Vector3 MyRotaion;
void Update () {
transform.SetPositionAndRotation(MyPosition, Quaternion.Euler( MyRotaion ));
// if you want to set it without a public reference do this:
transform.SetPositionAndRotation(new Vector3(0,0,0), Quaternion.Euler(new Vector3(0,0,0)));
// below you see how it's implemented for each property
// transform.position = MyPosition;
// transform.rotation = Quaternion.Euler(MyRotaion);
}
}
Answer by Bleakmountain50 · Nov 18, 2018 at 08:00 AM
So I looked around and couldn't find a way to get Transform.SetPositionAndRotation
to work so I used this code instead:
public Vector3 desiredPos;
public Quaternion desiredRot;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
transform.position = (desiredPos);
transform.rotation = (desiredRot);
}
}
i think desired rot won’t work without for example: quaternion.euler(vector3)
Answer by parizaval655321 · Nov 18, 2018 at 05:44 PM
Thank you guys so much! This is also my first time making my own project in Unity so I needed some help!
You should set @dan_wipf as the correct answer so he gets rewarded
Your answer
![](https://koobas.hobune.stream/wayback/20220612182316im_/https://answers.unity.com/themes/thub/images/avi.jpg)