- Home /
Please help me stop the flipping card!!!!!!!!!!
I am seriously going to explode... I have tried about 6 different ways to get a card to flip 180 degrees to show the other side but every single time the card just keeps on going. it never stops and i cannot figure out why. here is my current itteration. i have also tried to animate it but that was having the same problem, and i hate the new severe reliance on the animation controller; but i digress. please help!!!!
here is the flip section
void Update ()
{
if(_flip == true)
{
targetRotation = Quaternion.AngleAxis(180.0f, transform.forward) * transform.rotation;
}
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, smooth * Time.deltaTime);
}
here is the full code
using UnityEngine;
using System.Collections;
using System;
public class Flip : MonoBehaviour
{
//setup variables that are needed in script.
private Vector3 mousePos;
private GameObject _ts;
private Quaternion targetRotation;
private float smooth;
public GameObject obj;
private GameObject _obj;
public GameObject selectionMasterScript;
private bool _flip;
private Quaternion _rotation;
//public Animator animator;
// Use this for initialization
void Start ()
{
_ts = this.gameObject;
_rotation = this.gameObject.transform.rotation;
_flip = false;
//animator = GetComponent<Animator>();
selectionMasterScript = GameObject.FindGameObjectWithTag("SelectionMaster");
//declare variables starting condition.
targetRotation = transform.rotation;
smooth = 3.0f;
obj = null;
_obj = selectionMasterScript.GetComponent<SelectionMasterScript>().thing;
}
// Update is called once per frame
void Update ()
{
if(_flip == true)
{
targetRotation = Quaternion.AngleAxis(180.0f, transform.forward) * transform.rotation;
}
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, smooth * Time.deltaTime);
}
void OnMouseEnter ()
{
//obj is equal to what ever you are hovering over.
_obj = GetComponent<Collider> ().gameObject;
selectionMasterScript.GetComponent<SelectionMasterScript> ().thing = _obj;
//Debug.Log (_obj);
//Debug.Log ("enter");
}
void OnMouseOver()
{
//Debug.Log ("hovering");
if (Input.GetMouseButtonDown (0))
{
//animator.SetBool("Clicked", true);
_flip = true;
Debug.Log("Clicked");
}
}
void OnMouseExit()
{
_obj = null;
//Debug.Log (_obj);
//Debug.Log ("exit");
//Debug.Log (selected);
}
}
Your problem is in Update. Your Slerp function is outside of any if check so it just runs and runs and runs.
Lerp functions ONLY WOR$$anonymous$$ with a T factor between 0 and 1. Anything over 1 yields an instant TO condition.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Stop from showing point value 1 Answer