Area Effector 2D and the Animator not working together.
Windows 7 64bit environment (compiling to android) (testing in windows), 2D platformer'ish style game, Unity 5.1.2f1
Okay my issue right now is i have a 2D game with water and an "area effector 2d" used to make the player float. I want to make the water lower. so i added an animator and setup what i want to change from full water to low water. when i play the game the water lowers (from an animation adjusting the transform etc) but the area effector is no longer working during animation play? if i disable the animation the effect will come back, while debugging. i want the player to still float as the water lowers but he just drops all the way to the bottom.
Layout is Gameobject with Sprite Render, animator, Box Collider 2D, Area effector 2D and a controller script which doesn't do anything right now.
Again without animation the water works fine and the player kind of goes into the water and floats back up to the top.
Any ideas? Thanks.
Okay round two. I removed the animator. I added a script to adjust the localscale of the object. I get the same results. when adjusting the scale the "area effector 2D" has no effect on my player. Here is the function i used to modify scale. Not pretty but it works.
//$$anonymous$$axDistanceDelta is set to 0.02 and i have max scale at 8 and $$anonymous$$ at 2.
float currentDrainY = transform.localScale.y;
if(draining && (drain$$anonymous$$inY < currentDrainY))
{
//drain
transform.localScale = Vector3.$$anonymous$$oveTowards(transform.localScale,new Vector3(transform.localScale.x,drain$$anonymous$$inY,transform.localScale.z),$$anonymous$$axDistanceDelta);
}
else if(!draining && (drain$$anonymous$$axY > currentDrainY))
{
//fill
transform.localScale = Vector3.$$anonymous$$oveTowards(transform.localScale,new Vector3(transform.localScale.x,drain$$anonymous$$axY,transform.localScale.z),$$anonymous$$axDistanceDelta);
}
I created a empty object with the controller script attached so i could have a anchor point where i needed it. then attached the gameobject with the sprite render, collider and area effector to it. So i scale the empty object with the script and it makes the attached gameobject shrink or grow. but as soon as it starts to shrink/grow my player falls to the bottom and no longer floats.
Answer by pRoFlT · Aug 31, 2015 at 08:04 PM
I've posted this in the forum. And this link is my answer to my own question :)
I just wrote my own Area Effector 2D script. only works with one object. could use more work to be cleaner and be a direct replacement drop in for area effector 2D.
Your answer