Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Ohcrabs |
I hv created an rewind script and it works fine when it plays back position and rotation recorded when the object is in a state of motion but when it plays back the position and rotation recorded when the object is in a state of rest, the object gets stuck once it rewinds back to its original postion.
Here is my code pls help:-
extends RigidBody
var isrewinding: bool = false
var position: Array = PoolVector3Array()
var rot: Array = PoolVector3Array()
func _ready():
position = PoolVector3Array()
rot = PoolVector3Array()
func _record():
position.insert(0, transform.origin)
rot.insert(0, transform.basis)
func _rewind():
if isrewinding == true:
if position.size() > 0:
if rot.size() > 0:
transform.origin = position[0]
transform.basis = rot[0]
if position.size() > 1:
position.remove(0)
if rot.size() > 1:
rot.remove(0)
if isrewinding == false:
_record()
func _process(_delta):
if Input.is_action_just_pressed(“za rewindo”):
isrewinding = true
elif Input.is_action_just_released(“za rewindo”):
isrewinding = false
func _physics_process(_delta):
if isrewinding == true:
_rewind()
elif isrewinding == false:
_record()