Demigiant Forum
Unity Assets => DOTween & DOTween Pro => Topic started by: iron59 on July 17, 2015, 04:03:49 AM
-
Good day. I have several objects that are overlapping with each other in terms of position. I'm having a problem if I use the DOPunchPosition function such that, even though I have the same z value for the object's transform position and the punch function's direction, I'm still observing that the object changes in the z-position. Here's my code:
public void PunchSprite(Vector3 sourcePos, int distance = 5) {
if(this.tweener != null) {
this.tweener.Kill(true);
}
Vector3 monstPos = this.transform.position;
float angleRad = Mathf.PI + Mathf.Atan2(sourcePos.y - monstPos.y, sourcePos.x - monstPos.x);
float targetX = Mathf.Cos(angleRad);
float targetY = Mathf.Sin(angleRad);
Vector3 targetPos = new Vector3(targetX, targetY, monstPos.z);
this.tweener = this.transform.DOPunchPosition(targetPos, 0.2f, distance, 1, false);
}
What I would like is to use the punch function without the object chaning its z-position. Any suggestions on how to fix this? Thanks in advance.
-
Chain an OnComplete to set it back to the original value.
this.tweener = this.transform.DOPunchPosition(targetPos, 0.2f, distance, 1, false).OnComplete(()=>this.transform. position = monstPos);
-
I also need to maintain the z-position for the entire duration of the punch because it overlaps another sprite (z-wise) for a split second while in the punch motion. Is this possible?
-
Hi and sorry for the late reply (and thanks jprocha101 for the help),
To maintain the Z, just write 0 for the Z value of the Punch.