Hi all,
I have (I think) a very tricky problem.
Let’s say we have a player and an enemy, both have boxcollider2d and rigidbody2d with respectively istrigger and iskinematic set in the inspector.
The player has a sword which has a boxcollider2d and rigidbody2d just like the player (sword is a child of player). The sword has an AnimationComponent with animatePhysics checked, there is one animation for each direction (North, East, West, South) and the animation is a always a rotation and a position curves (sword slashing).
Now, I want the animation of the sword slashing to start at some position (it’s just like an orbital camera), so I changed the localPosition of the sword and there it is : I have an orbital slashing sword.
But actually, even if the animation is correctly done, the update physics doesn’t work, the sword collides with the enemy and trigger his collider. So I checked and the most logical answer is that the position of the animation isn’t updated for the animatePhysics loop.
Here is a screen of my player (on the left) and the enemy (on the right) when the sword collide :
And this is my Update method :
void Update()
{
if (!_animation.isPlaying)
{
_renderer.enabled = false;
}
if (_animationToPlay.Equals("sword_front") || _animationToPlay.Equals("sword_back"))
{
transform.position = (_lastPosition - _playerController.collider2D.bounds.center).normalized * 0.25f;
transform.localPosition = (_lastPosition - _playerController.collider2D.bounds.center).normalized * 0.25f;
}
else
{
transform.position = (_lastPosition - _playerController.collider2D.bounds.center).normalized * 0.20f;
transform.localPosition = (_lastPosition - _playerController.collider2D.bounds.center).normalized * 0.20f;
}
}
Thanks