- Home /
switch controlling transform
Hello everyone, I'd like to ask for help with a little issue
I'm having. What I'm trying to do is have a script that will rotate an
object based on mouse input. I'd also want to switch the
transform I'm doing the rotation on to a different object's
during run time. I'm having an issue with my script, when I press the button to
switch to another object's transform, it works fine. but when I press button to go back to the previous transform,
it's X rotation is immediately changed to 90.:confused: This
also happens if let's say I'm on object 1 and I press key to go
to object 1. I've been looking over this for a while now, I'm just not sure
what I'm doing wrong. Thank you in advance !!
public class TestRotateSwitch : MonoBehaviour
{
public Transform transCur;
public Transform ref1;
public Transform ref2;
private float xrot;
private float xRotCur;
public float xrotspeed;
private float _ref_X_Velocity;
private float yrot;
private float yRotCur;
public float yRotSpeed;
private float _ref_Y_Velocity;
void Start ()
{
transCur = ref1;
}
void Update ()
{
if(Input.GetKeyUp (KeyCode.Q))
{
yrot = ref1.rotation.eulerAngles.y;
xrot = ref1.rotation.eulerAngles.x;
yRotCur = yrot;
xRotCur = xrot;
transCur = ref1;
transCur.rotation = ref1.rotation;
}
if(Input.GetKeyUp (KeyCode.E))
{
yrot = ref2.rotation.eulerAngles.y;
xrot = ref2.rotation.eulerAngles.x;
yRotCur = yrot;
xRotCur = xrot;
transCur = ref2;
}
yrot += yRotSpeed * Time.deltaTime * Input.GetAxis
("Mouse X");//InputManager_IG.MovingStick.StickPosition.x ;
xrot -= xrotspeed * Time.deltaTime *
Input.GetAxis ("Mouse
Y");//InputManager_IG.MovingStick.StickPosition.y ;
xrot = Mathf.Clamp (xrot,-90,90);
yRotCur = Mathf.SmoothDamp (yRotCur,yrot, ref
_ref_Y_Velocity,0.000001f);
xRotCur = Mathf.SmoothDamp (xRotCur,xrot, ref
_ref_X_Velocity,0.000001f);
transCur.rotation = Quaternion.Euler (new
Vector3(xRotCur,yRotCur,0));
}
}
Your answer
Follow this Question
Related Questions
how to reset a transform.rotate 1 Answer
switch character 1 Answer
transform.localPosition problem. 0 Answers
Resetting a gameobjects position? 1 Answer
Error With Switching Characters 1 Answer