Skip to content

Commit eee6d7f

Browse files
committed
- Add doNotTurnToPointingEntity option, if it TRUE it will not turn playing character to pointing entity.
- Add `buildingRotateSpeed`, it will be used while `buildRotationSnap` is `FALSE` to turn building by speed not fixed rotating angles.
1 parent 00f7f83 commit eee6d7f

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

Scripts/AimAtCursorPlayerCharacterController.cs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public class AimAtCursorPlayerCharacterController : BasePlayerCharacterControlle
1212
[SerializeField]
1313
protected FollowCameraControls minimapCameraPrefab;
1414

15+
[Header("Controller Settings")]
16+
[SerializeField]
17+
protected bool doNotTurnToPointingEntity;
18+
1519
[Header("Building Settings")]
1620
[SerializeField]
1721
protected bool buildGridSnap;
@@ -23,6 +27,8 @@ public class AimAtCursorPlayerCharacterController : BasePlayerCharacterControlle
2327
protected bool buildRotationSnap;
2428
[SerializeField]
2529
protected float buildRotateAngle = 45f;
30+
[SerializeField]
31+
protected float buildRotateSpeed = 200f;
2632

2733
protected bool isLeftHandAttacking;
2834
protected bool isSprinting;
@@ -345,19 +351,25 @@ protected void UpdateLookInput()
345351
tempTargetPosition = (tempGameEntity as IDamageableEntity).OpponentAimTransform.position;
346352
else
347353
tempTargetPosition = tempGameEntity.GetTransform().position;
348-
if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D)
349-
lookDirection = (tempTargetPosition - CacheTransform.position).normalized;
350-
else
351-
lookDirection = (XZ(tempTargetPosition) - XZ(CacheTransform.position)).normalized;
354+
if (!doNotTurnToPointingEntity)
355+
{
356+
if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D)
357+
lookDirection = (tempTargetPosition - CacheTransform.position).normalized;
358+
else
359+
lookDirection = (XZ(tempTargetPosition) - XZ(CacheTransform.position)).normalized;
360+
}
352361
}
353362
break;
354363
}
355364
else
356365
{
357-
if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D)
358-
lookDirection = (physicFunctions.GetRaycastPoint(i) - CacheTransform.position).normalized;
359-
else
360-
lookDirection = (XZ(physicFunctions.GetRaycastPoint(i)) - XZ(CacheTransform.position)).normalized;
366+
if (!doNotTurnToPointingEntity)
367+
{
368+
if (GameInstance.Singleton.DimensionType == DimensionType.Dimension2D)
369+
lookDirection = (physicFunctions.GetRaycastPoint(i) - CacheTransform.position).normalized;
370+
else
371+
lookDirection = (XZ(physicFunctions.GetRaycastPoint(i)) - XZ(CacheTransform.position)).normalized;
372+
}
361373
}
362374
}
363375
}
@@ -546,11 +558,30 @@ public Vector3 GetMoveDirection(float horizontalInput, float verticalInput)
546558
buildYRotate = 0f;
547559
}
548560
// Rotate by keys
549-
if (InputManager.GetButtonDown("RotateLeft"))
550-
buildYRotate -= buildRotateAngle;
551-
else if (InputManager.GetButtonDown("RotateRight"))
552-
buildYRotate += buildRotateAngle;
553-
ConstructingBuildingEntity.Rotation = GetBuildingPlaceRotation(buildYRotate);
561+
Vector3 buildingAngles = Vector3.zero;
562+
if (CurrentGameInstance.DimensionType == DimensionType.Dimension3D)
563+
{
564+
if (buildRotationSnap)
565+
{
566+
if (InputManager.GetButtonDown("RotateLeft"))
567+
buildYRotate -= buildRotateAngle;
568+
if (InputManager.GetButtonDown("RotateRight"))
569+
buildYRotate += buildRotateAngle;
570+
// Make Y rotation set to 0, 90, 180
571+
buildingAngles.y = buildYRotate = Mathf.Round(buildYRotate / buildRotateAngle) * buildRotateAngle;
572+
}
573+
else
574+
{
575+
float deltaTime = Time.deltaTime;
576+
if (InputManager.GetButton("RotateLeft"))
577+
buildYRotate -= buildRotateSpeed * deltaTime;
578+
if (InputManager.GetButton("RotateRight"))
579+
buildYRotate += buildRotateSpeed * deltaTime;
580+
// Rotate by set angles
581+
buildingAngles.y = buildYRotate;
582+
}
583+
}
584+
ConstructingBuildingEntity.Rotation = Quaternion.Euler(buildingAngles);
554585
// Find position to place building
555586
if (InputManager.useMobileInputOnNonMobile || Application.isMobilePlatform)
556587
FindAndSetBuildingAreaByAxes(aimAxes);
@@ -644,25 +675,6 @@ protected Vector3 GetBuildingPlacePosition(Vector3 position)
644675
return position;
645676
}
646677

647-
protected Quaternion GetBuildingPlaceRotation(float angles)
648-
{
649-
Vector3 eulerAngles = Vector3.zero;
650-
if (CurrentGameInstance.DimensionType == DimensionType.Dimension3D)
651-
{
652-
if (buildRotationSnap)
653-
{
654-
// Make Y rotation set to 0, 90, 180
655-
eulerAngles.y = Mathf.Round(angles / 90) * 90;
656-
}
657-
else
658-
{
659-
// Rotate by set angles
660-
eulerAngles.y = angles;
661-
}
662-
}
663-
return Quaternion.Euler(eulerAngles);
664-
}
665-
666678
protected Vector2 XZ(Vector3 vector3)
667679
{
668680
return new Vector2(vector3.x, vector3.z);

0 commit comments

Comments
 (0)