Skip to content

Commit

Permalink
Create MoveRigidBodyWorldSpace.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
magx2 committed Jul 26, 2021
1 parent 7dfd232 commit fe3f94b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions MoveRigidBodyWorldSpace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using UnityEngine;

namespace Misc
{
[RequireComponent(typeof(Rigidbody))]
public class MoveRigidBodyWorldSpace : MonoBehaviour
{
[SerializeField] private Vector3 speed = new Vector3(1, 1, 1);

private Rigidbody _rigidbody;

private void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
}

private void FixedUpdate()
{
var deltaSpeed = speed * Time.fixedDeltaTime;
_rigidbody.MovePosition(_rigidbody.position + deltaSpeed);
}
}
}

0 comments on commit fe3f94b

Please sign in to comment.