I am making a card game. I am trying to create an effect when player plays his/her card.
I would like to rotate the card as it moves to the destination ( another gameObject in middle of the board ). When card reaches the destination it should be aligned with the destination’s rotation.
I tried following code without success. The card seems to rotate as long as it reaches the destination’s rotation. I want continious rotation
void Start(){
rotateAtoB=true;
startDistance=Vector3.Distance(transform.position,endPos.transform.position);
}
void Update(){
if(rotateAtoB){
float delta= 1 - Mathf.Pow(Vector3.Distance(transform.position,endPos.transform.position)/startDistance,5.0f/9.0f);
transform.rotation=Quaternion.Slerp(transform.rotation,endPos.transform.rotation,(delta/startDistance)*1.0f);
if(Mathf.Approximately(delta,1)){
rotateAtoB=false;
}
}
transform.position=Vector3.MoveTowards(transform.position,endPos.transform.position,2.0f*Time.deltaTime);
}
I am also thinking about AddTorque method, but not sure if this is what I want.
Any ideas how to move forward?