Skip to content

Commit 1b97806

Browse files
committed
Little Tweaks
- Added a method to rotate Vector2 - Added a method to check if a controller belongs to a Play Station.
1 parent 6b11bc2 commit 1b97806

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

Runtime/Scripts/InputUtilities.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public static Dictionary<ControllerType, int> GetControllers()
4848
return dict;
4949
}
5050

51+
public static bool IsDualshock(ControllerType controller) =>
52+
controller == ControllerType.Dualshock3 || controller == ControllerType.Dualshock4;
53+
5154
private static Dictionary<ControllerType, int> TryIncrementValue(Dictionary<ControllerType, int> dict,
5255
ControllerType controller)
5356
{

Runtime/Scripts/MathUtilities.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,22 @@ public static Vector3 Direction(Vector3 start, Vector3 target)
261261
return (heading / distance).normalized;
262262
}
263263

264+
/// <summary>
265+
/// This method takes in a vector2 and rotates it by the angle given in radians.
266+
/// </summary>
267+
/// <param name="angle"> The angle to rotate in radians.</param>
268+
/// <returns></returns>
269+
public static Vector2 RotateVector2(Vector2 vector, float angle)
270+
{
271+
var cos = Mathf.Cos(angle);
272+
var sin = Mathf.Sin(angle);
273+
274+
return new Vector2(
275+
cos * vector.x - sin * vector.y,
276+
sin * vector.x + cos * vector.y
277+
);
278+
}
279+
264280
#region Audio
265281

266282
public static float FloatToDecibel(float f)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.dartcore.utilities",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"displayName": "DartCore Utilities",
55
"description": "This package contains methods to handle commonly required stuff.",
66
"unity": "2018.1",

0 commit comments

Comments
 (0)