yurakr

Can someone help me? I want to flip my 2D character in the 2D game to LEFT when the bone of a hand or a gun pointing to LEFT and then when bone points to RIGHT flip it again. It needs to be simple but I can not figure it out.

Note: bone pointing toward the mouse position(cross bone made in Spine).
yurakr
  • Сообщения: 4

badlogic

I suppose if you really only want a left/right flip based on where a gun/hand bone should be looking, simply check the x-coordinate of the mouse against the x-coordinate of your skeleton. If the mouse x > skeleton x, the skeleton should point to the right, otherwise to the left.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2013

yurakr

Thanks for trying to help. The problem is that I am using Cross(bone inside Spine) like in this example:
http://ru.esotericsoftware.com/spine-examples-spineboy

I can flip character properly one time (for example from LEFT to RIGHT), but when after that I am doing it again (from RIGHT to LEFT) my hero starts constantly flipping. There must be a simple solution to this.
yurakr
  • Сообщения: 4

badlogic

Mouse cursor following of the arm by using an IK target like in the Spineboy example is separate from flipping the skeleton if the mouse cursor gets to the other side of the character.

What you describe seems to be a minor bug in your flipping logic. Post the code snippet responsible for the flipping part and I might be able to help.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2013

yurakr

This is my code:
void FlipByCross()
{
//Flip Player by Cross
if(objectCross.transform.position.x > rootBoneCross.transform.position.x)
{
skeletonAnimation.skeleton.FlipX = false;
}

if(objectCross.transform.position.x < rootBoneCross.transform.position.x)
{
skeletonAnimation.skeleton.FlipX = true;
}
}
objectCross is my cross and rootBoneCross is a root of Spine Character

When I am trying to do a method above my Character flipping constantly.

But this part works:
void FlipByCross()
{
//Flip Player by Cross
// if(objectCross.transform.position.x > rootBoneCross.transform.position.x)
// {
// skeletonAnimation.skeleton.FlipX = false;
// }

if(objectCross.transform.position.x < rootBoneCross.transform.position.x)
{
skeletonAnimation.skeleton.FlipX = true;
}
}
yurakr
  • Сообщения: 4

badlogic

Hm, the code looks correct. I'm afraid without being able to debug it locally myself it's hard to tell what's going on. You could add console logging to both if branches and see if they actually get executed all time. That would indicate that something's (re-)setting your objectCross or rootBoneCross position all the time.
Аватара пользователя
badlogic

Mario
  • Сообщения: 2013

yurakr

Character constantly flipping.
In Console:
Debug.Log("FlipRight"+ rootBoneCross.transform.position.x);
FlipRight-3,43
Debug.Log("FlipLeft"+ rootBoneCross.transform.position.x);
FlipLeft-3,43
Number changes when I move character but always Left & Right numbers are identical(same). I think numbers changes related to screen(camera).

Debug.Log("FlipRightCross"+ objectCross.transform.position.x);
FlipRightCross-7,104
Debug.Log("FlipLeftCross"+ objectCross.transform.position.x);
FlipRightCross-3,335
Number changes always Left & Right numbers are different(cross each flip on other side of character). Numbers changes related to screen(camera).

Maybe this info will help.
yurakr
  • Сообщения: 4

Harald

Unfortunately this still shows nothing obviously wrong.

I would guess that the problem is that your reference bone is flipped over to the other side as well and does not lie on the flipping-axis, thus ending in infinite flipping. You could try if something more stable (e.g. the GameObject transform's position) works as a point of reference. If yes, then you can be sure that the flipping reference bone is the cause of your problem.
Аватара пользователя
Harald

Harri
  • Сообщения: 950


Вернуться в Runtimes