I have a simple scene of 2 boxes . box A is static and box B rotates around box A . simple stuff . So I get box B to rotate 180 degrees around box A , however, its rotating too fast . how does one slow the speed down? . i tried to cahnge the rotation limit values as well as dtheta but it still persists. Can anyone help ? here is the script :
var rotation_origin
export var r = 1
var transition_point = Vector3.ZERO
var theta
var dtheta = 2 * PI / 250
var rotationLimit = PI / 6.5
var boxA
var boxB
var stopping_distance = 1.0
var velocity = Vector3.ZERO
var move_speed = 2.0
var blend_timer = 0.0
var blend_duration = 7.0 # Adjust the duration of the blend
var state = states.IDLE
enum states {
IDLE
SEEK
ROTATE
}
func _ready():
boxA = get_node("../boxA")
boxB = get_node("../boxB")
func _process(delta):
rotateAround(delta)
func rotateAround(delta):
match state:
states.IDLE:
var direction_to_player = get_node("../boxA").global_transform.origin - global_transform.origin
var distance_to_player = direction_to_player.length()
if distance_to_player < stopping_distance:
velocity = Vector3.ZERO
else:
state = states.SEEK
states.SEEK:
var direction_to_player = boxA.global_transform.origin - global_transform.origin
var distance_to_player = direction_to_player.length()
direction_to_player = direction_to_player.normalized()
if distance_to_player > stopping_distance:
velocity = direction_to_player * move_speed
move_and_slide(velocity)
elif distance_to_player < stopping_distance:
state = states.ROTATE
theta = Vector3(0, 0, 1).angle_to(boxB.global_transform.origin - global_transform.origin)
rotationLimit
states.ROTATE:
# In ROTATE state
rotation_origin = boxB.global_transform.origin - boxA.global_transform.origin
theta += dtheta
if theta <= rotationLimit:
var cosTheta = cos(theta)
var sinTheta = sin(theta)
var rotated_offset = Vector2(cosTheta * rotation_origin.x - sinTheta * rotation_origin.z,
sinTheta * rotation_origin.x + cosTheta * rotation_origin.z)
boxB.transform.origin = boxA.global_transform.origin + Vector3(rotated_offset.x, 0, rotated_offset.y)
#boxB.transform.origin.x = boxA.global_transform.origin.x + r * cosTheta
#boxB.transform.origin.z = boxA.global_transform.origin.z + r * sinTheta
#boxB.transform.origin.y = boxA.global_transform.origin.y
else:
theta = rotationLimit # Stop the rotation at the limit
state = states.IDLE