Making a sword follow mouse movement
hey everyone, I'm currently trying to make an arena slasher game and am trying to implement a mechanic that allows the player to control the movement of their sword by holding down the left mouse button and using the mouse movement to swing the sword around.
I'm new to coding with c# and unity in general but this is what I have so far. it's not much but it is a start in the right direction. I have no idea if this is the right way to go about it by any means.
public class wepswing : MonoBehaviour
{
void Start()
{
}
void Update()
{
if (Input.GetMouseButtonDown(0))
transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.5f));
}
}
any help or sample code to help give me an idea of how to even go about this would be greatly appreciated thanks.
Answer by Cyrusc · Jan 07, 2018 at 07:13 AM
Check out this video using Final IK https://www.youtube.com/watch?v=OhCtiV5r8HA
It uses a swinging animation that is manipulated to have a weapon aim at an object. You could instead change it to look at a normalized vector of the cameras raycast for first person. Or, you could expand on the offset abilities it was talking about to use the acceleration from the mouse.
Your answer
Follow this Question
Related Questions
Joystick Movement Not Smooth Enough 0 Answers
1st Person shooter, move player forward where cam is facing 1 Answer
How do I make my player model rotate based on the direction he is walking. 0 Answers
I don't know why my script wont work 1 Answer
GoogleVR / C# - How to, with the "pointer click": click 1 move a cube and click 2 move back the cube 0 Answers