Hi,
I am trying to setup my game to work with a controller but I'm having issues with getting the thumbstick to control where my character is aiming.
I followed these instructions by Pharan to setup the mouse input and that works great.
Spine Unity - Making the arm follow the mouse
I thought I was getting close by creating a vector3 and getting the x and y axis of the thumbstick as it moved but it's not working.
This almost works but doesn't update the direction while the thumbstick is moving:
void SkeletonAnimation_UpdateWorld (ISkeletonAnimation animated) {
var bonePosition = bone.GetWorldPosition(this.transform);
var direction = targetPosition - bonePosition;
float rotation = DirectionToRotation(direction, this.transform);
float parentRotation = bone.parent.WorldRotationX;
bone.RotateWorld(rotation - parentRotation);
}
static float DirectionToRotation (Vector3 direction, Transform transform) {
var localDirection = transform.InverseTransformDirection(direction);
return Mathf.Atan2(localDirection.y, localDirection.x) * Mathf.Rad2Deg;
}
Any help would be appreciated.
Thank you,
Seth Rolfe