Hello, i´m trying to rotate an object by 1 degree every time i press a button, the following works BUT if i ran in a slower cpu hops some frames: i.e: rotation_degrees.z +=1
rotate by 1 degree
How are you calling rotation_degrees.z += 1
? Are you calling it with Input.is_action_pressed
(called even when button is held down) or Input.is_action_just_pressed
(called only on initial press)?
If your calling the rotation_degrees from the physics process function, then the physics engine could be lagging because of slower cpu.
You probably want that button code to either be a signal on the button, or handled in _input(). Otherwise there could be effects from the framerate. Also, that method only works for a single click. If you are holding the button, you will need to use delta (time) so the object rotates the same speed at differing fps.
@cybereality said: You probably want that button code to either be a signal on the button, or handled in _input(). Otherwise there could be effects from the framerate. Also, that method only works for a single click. If you are holding the button, you will need to use delta (time) so the object rotates the same speed at differing fps.
Yes! and for all comments it works in _physics_process... but laggy on slower cpus.
how can i use delta in this case? rotation_degrees = Vector3(0,lerp_angle(rotation_degrees.z, rotation_degrees.z - 1.0, 1.0 * delta),0) rotate_z(rotation_degrees.z - 1.0)#multiplied by delta?
i've been tried the codes above but you cant change by angles in the docs they say to don't think in angles... they say the code
rotation_degrees is for the editor only but it works when running so.... i use that method xD
i'm struggling with the rotation to be the same on lower cpu's
if i put my code in the _input(event) only executes on every touch... i need to keep rotating if the button keeps pressed <-- this is the reason to put the code in physics process..
maybe i can put a while loop inside the input?
You can use _physics_process() if you want, but instead of 1.0, use a value that is the degrees rotated per second (a value you make up).
var deg_per_sec = 60.0
rotation_degrees.z += delta * deg_per_sec
The delta should help you get the rotation in sync on the two cpu. Time elapsed from last call is what that is. So on a slower cpu it will be a bigger number.