Mouse Follow Aim with IK - 2D Bowman
I'm developing a simple 2D bowman game. I'm trying to implement an aiming system whereby the bowman follows the position of the mouse. I want to use IK to make the graphics look more realistic, so I have two bones, one for the body and another for the arm and head, these appear to work fine.
I have an object for the arm bone with the following script
using UnityEngine;
using System.Collections;
public class Aim_Script : MonoBehaviour
{
void Update()
{
var pos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
pos = Camera.main.ScreenToWorldPoint(pos);
transform.position = pos;
}
}
I've then added a Fabrik IK solver to my player sprite, set the object as the effector, set the chain length to 2 (so it only affects the joints on the arm) and generated a target. When I test this, the player sprite spins around and stutters, I can fix this by adjusting the weight, but then it doesn't follow the mouse properly. I suspect that the IK solver is struggling to solve with pos, but I've been at this for a few hours now and I can't wrap my head around it :(
Your answer
Follow this Question
Related Questions
Moving dotted guide line 0 Answers
2D top down shooter can only aim to the top right (mouse aim) 0 Answers
Aim at my cursor 1 Answer
How to aim at crosshair in a 2D game? 0 Answers
2D gun aiming problem 1 Answer