# Need a little more help with rotating sword around player (Unity 2D)

Game Development Asked by Gus K on December 23, 2020

this question is somewhat similar to my last question (found here). This time, I have upgraded to the new Input Manager and updated the script that uses the controller, but now I’m having trouble with having the sword rotate around the player and towards the mouse. The image below might help visualize this better.

Here’s my current code:

public void Update()
{
var mouse = Mouse.current;
if (controllerControl)
{
}
else
{
x = mouse.position.ReadValue().x; //Here's where I think the problem is
}

//convert the input into an angle in radians, and convert that into degrees

//use trig to position sword
//rotate to face away from center. note that the angle atan gives us is
//oriented differently than unity's rotation, so we have to reverse it
sword.localEulerAngles = new Vector3(0, 0, degrees - 90);
}

The boolean "controllerControl" will change based on which input device the player chooses. The sword is a child of a box object. If someone could point me in the right direction, that would be much appreciated.

I found the answer by myself, but if this is not best practice then please let me know.

var mouse = Mouse.current;
if (controllerControl)
{
}
else
{
x = v2.x - box.transform.position.x;
y = v2.y - box.transform.position.y;

}

This solution requires a new Camera 'cam' if someone else wants to use this.

Correct answer by Gus K on December 23, 2020

## Related Questions

### How to move a character from 1 to 3 squares on a grid?

0  Asked on January 23, 2021 by shunkashuu

### How can I spawn random objects on a plane area even if the plane position is not 0,0,0 and how to spawn also with random height?

1  Asked on January 17, 2021 by shamen-raze

### Unity 2017.3.of3 Raycast2D randomly misses objects

1  Asked on January 15, 2021 by hesitatetowonder

### How to fix the vibration while colliding?

1  Asked on January 13, 2021

### Render order in 3/4 view game

0  Asked on January 10, 2021 by chuan-li

### How can I control ads frequency?

1  Asked on January 10, 2021 by ruslan-plastun

### Attach movement to each list object

1  Asked on January 9, 2021 by mavish

### How to make a map surface object

1  Asked on January 8, 2021 by anonymous-entity

### Coding Spelunky Edge Roll Mechanic

0  Asked on January 5, 2021 by austin-weaver

### Creating a lookup table of datamaps in Harlowe/Twine

0  Asked on January 4, 2021 by the_e

### Unity 4 – Some Rigidbodies Won’t Fall Asleep

5  Asked on January 3, 2021 by ryan-berserkguard-nrby

### Wall sliding in JavaScript; works, but gets stuck at corners

1  Asked on December 31, 2020 by bluejayke

### Unity PackageCache keeps having errors

0  Asked on December 31, 2020 by christopher-perry

### Phaser Tiled map importing

1  Asked on December 30, 2020 by kabuto178

### Change the colour of all particles on screen

1  Asked on December 27, 2020 by super-potato

### How can you make a jump to a point using the Character Controller?

0  Asked on December 25, 2020 by aimon-z

### Need a little more help with rotating sword around player (Unity 2D)

1  Asked on December 23, 2020 by gus-k

### Trouble destroying an SDL2 texture from another class

1  Asked on December 21, 2020 by gamer1

### How to hide objects behind an invisible plane?

1  Asked on December 18, 2020 by hatinacat2000