Code Improvement Help : moving object inside radius buggy ( DOTween & without )
ok guys i've created my 2D game's mechanics and there where SO MANY BUGS but i did debug it,ofcourse its not good because its buggy again so i need some help,i'm moving an ball inside a circle radius by its Y axes and when it goes maximum distance it starts going -Y and its kind of buggy check out the code :
if (_Distance < 2.31f)
{
if(_switch == 0)
transform.Translate (0, 3.5f * Time.deltaTime, 0);
else if(_switch == 1)
transform.Translate (0, -3.5f * Time.deltaTime, 0);
the switch is just for me to know when to go -y or +y axes code here :
switch (_switch)
{
case 0: _switch = 1;
transform.Translate (0, -3.5f * Time.deltaTime, 0);
break;
case 1: _switch = 0;
transform.Translate (0, 3.5f * Time.deltaTime, 0);
break;
}
this is so hardcoded... i have added the translate functions here because without it the ball gets confused and doesnt move because when it starts to move back the distance is the same
any better solution? ALSO I would like to make it move with DOTween but can't find a way to make this kind of mechanics
the switch
is connected to the if
with else
statement so i made it else if ( _Distance >= 2.31f)
Your answer
Follow this Question
Related Questions
To know what is in a circle, use circle collider or Vector3.Distance? 2 Answers
"Pushing" 2D Objects without applying a force? 0 Answers
Prefab Sphere Collider reset it's radius 0 Answers
How to make a player teleport on collision? 2 Answers
How to move an object on a terrain that will always stay on top of the terrain? 2 Answers