Skip to content
Snippets Groups Projects

changed movement to forces instead of translation

Merged Christoph Julian Mayerhofer requested to merge rewriteMovementOfKings into main
1 file
+ 19
3
Compare changes
  • Side-by-side
  • Inline
@@ -20,12 +20,20 @@ public class KingController : MonoBehaviour
private int shadePosition = 0;
public Sprite weakAgainst;
private Rigidbody2D _rb;
// Start is called before the first frame update
void Start()
{
Shade(0);
_rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
//fixed speed;
_rb.velocity = _rb.velocity.normalized * kingSpeed;
}
// Update is called once per frame
void Update()
{
@@ -66,8 +74,16 @@ public class KingController : MonoBehaviour
// Calculate movement direction
Vector3 movementDirection = new Vector3(horizontalInput, verticalInput, 0f);
// Apply movement
transform.position += movementDirection * kingSpeed * Time.deltaTime;
// Apply movement with RigidBody so the body continues the slide and better to control
if (movementDirection.magnitude > 0.1)
{
var rb = GetComponent<Rigidbody2D>();
rb.velocity = movementDirection;
}
// Apply movement with Translation
//transform.position += movementDirection * kingSpeed * Time.deltaTime;
// shade
if (killCounter == killsNeeededToShade)
Loading