Skip to content

Instantly share code, notes, and snippets.

@daichi-takezawa
Last active May 1, 2022 11:08
Show Gist options
  • Save daichi-takezawa/da59fbe0511439fced8181ec2ce14516 to your computer and use it in GitHub Desktop.
Save daichi-takezawa/da59fbe0511439fced8181ec2ce14516 to your computer and use it in GitHub Desktop.
Vector3 movingDirecion;
public float speedMagnification; //調整必要 例10
public RigidBody rb;
public Vector3 movingVelocity;
void Start(){
rb = Getcomponent<RigidBody>();
}
void Update() {
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
movingDirecion = new Vector3(x, 0, z);
movingDirecion.Normalize();//斜めの距離が長くなるのを防ぎます
movingVelocity = movingDirecion * speedMagnification;
}
void FixedUpdate() {
if (jumpNow == true) return;
rb.velocity = new Vector3(movingVelocity.x, rb.velocity.y, movingVelocity.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment