Skip to content

Instantly share code, notes, and snippets.

@daichi-takezawa
Created April 29, 2021 12:00
Show Gist options
  • Save daichi-takezawa/72393d40a15eaeee38051271dbac094e to your computer and use it in GitHub Desktop.
Save daichi-takezawa/72393d40a15eaeee38051271dbac094e to your computer and use it in GitHub Desktop.
Update() {
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.D)) {
stopRigidbody = true;
}
}
FixedUpdate() {
if (stopRigidbody == true) {
rb.velocity = Vector3.zero;
stopRigidbody = false;
}
float speedMag = targetVelocity - rb.velocity.magnitude;
rb.AddForce(movingDirecion * speedMag, ForceMode.Force);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment