Skip to content

Instantly share code, notes, and snippets.

@ShiftedClock
Last active November 8, 2019 22:27
Show Gist options
  • Select an option

  • Save ShiftedClock/8d12a835feb7d9c257d08a57a88b7af8 to your computer and use it in GitHub Desktop.

Select an option

Save ShiftedClock/8d12a835feb7d9c257d08a57a88b7af8 to your computer and use it in GitHub Desktop.
using UnityEngine;
public class PolarCharacterController {
[SerializeField] private float moveSpeed;
private PolarCoordinate pc;
public void Awake () {
pc = new PolarCoordinate(transform);
}
public void Update () {
if (Input.GetAxis("Horizontal")) {
MoveHorizontal(moveSpeed * Time.deltaTime);
}
if (Input.GetAxis("Vertical")) {
MoveVertical(moveSpeed * Time.deltaTime);
}
//? Big unknown: Is the angle factor for diagonal movement the same as for a 2D CharacterController on a plane?
// i.e. sqrt(2)/2
// Actually, it is strange that the further you go from the center, the faster you're moving.
// But in the world of this game that actually makes sense.
}
public MoveHorizontal () {
//? Should the logic be contained in here or in the PolarCoordinate class?
//pc.angle
}
public MoveVertical () {
//pc.
}
}
public class PolarCoordinate {
private float dist;
public float Dist {
get => dist;
//TODO: set => update transform
};
private float angle;
public float Angle {
get => angle;
//TODO: set => update transform;
};
private Transform transform;
public PolarCoordinate (Transform transform) {
this.transform = transform;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment