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.