extends CharacterBody3D
@export var rotation_speed = 3
@export var platform_size = 1
@export var platform_count = 4
@export var platform_distance = 3
func _ready() -> void:
var platforms : Array[Node] = [$Platform,$Platform2,$Platform3,$Platform4]
if platform_count<4:
for i in 4-platform_count:
platforms.get(i).queue_free()
for i in platform_count:
platforms.get(i).scale.x = platform_size
platforms.get(i).scale.z = platform_size
for i in platform_count:
if i == 0:
platforms.get(i).position.x = platform_distance
elif i ==1:
platforms.get(i).position.x = -platform_distance
elif i ==2:
platforms.get(i).position.z = platform_distance
elif i==3:
platforms.get(i).position.z = -platform_distance
func _process(delta: float) -> void:
velocity=velocity.rotated(Vector3.UP.normalized(),rotation_speed*delta)
rotation+=velocity
Use AnimatableBody3D for each platform instead of a CollisionShape3D, and put them under a Node3D instead of a CharacterBody3D. Then just update the position of the the AnimatableBody3D objects.
extends Node3D
## The number of degrees the platform rotates per second.
@export var rotation_speed: float = 30.0
func _physics_process(delta: float) -> void:
rotation.x += deg_to_rad(rotation_speed) * delta
If you want the platforms to stay facing up, this is the code for them:
extends AnimatableBody3D
## The number of degrees the platform rotates per second.
@export var rotation_speed: float = -30.0
func _physics_process(delta: float) -> void:
rotation.x += deg_to_rad(rotation_speed) * delta
Obviously, you could combine the two scripts into one as you did.
extends Node3D
## The number of degrees the platform rotates per second.
@export var rotation_speed: float = 30.0
func _physics_process(delta: float) -> void:
rotation.x += deg_to_rad(rotation_speed) * delta
for node in get_children():
if node is AnimatableBody3D:
node.rotation.x += deg_to_rad(-rotation_speed) * delta
You are doing way too much in your code. If you want to rotate on the z-axis, you can add that code in with another export variable and another line or two of code.
it’s unusably buggy (i edited it slightly, but only by removing the deg_to_rad as my rotation speed variable is already in rads, and by changing the rotation axis), but it’s a lot closer to what i want, so thank you.
right now the issue is that upon spawning in the level, the “carousel“ as i like to call it will flash in the middle and all the places where it’s platforms would be for a seemingly random amount of time until suddenly either working as intended:
Well I created and ran a test project and didn’t have that problem, and it’s based on code I have in published games. So I’m thinking it’s related to the changes you made. So it would help to see the code you ended up with.
Also, are those plane meshes? That could be related to the problem. What’s their culling set to? What happens if you change them to box meshes? Same problem?
same problem if i switch them to box meshes, and the hitboxes are already boxes.
code:
extends Node3D
@export var rotation_speed = 1
@export var platform_size = .5
@export var platform_count = 4
@export var platform_distance = 3
func _ready() -> void:
var platforms : Array[Node] = [$Platform,$Platform2,$Platform3,$Platform4]
if platform_count<4:
for i in 4-platform_count:
platforms.get(i).queue_free()
platforms.pop_at(i)
for i in platform_count:
platforms.get(i).scale.x = platform_size
platforms.get(i).scale.z = platform_size
for i in platform_count:
if i == 0:
platforms.get(i).position.x = platform_distance
elif i ==1:
platforms.get(i).position.x = -platform_distance
elif i ==2:
platforms.get(i).position.z = platform_distance
elif i==3:
platforms.get(i).position.z = -platform_distance
func _process(delta: float) -> void:
rotation.y += rotation_speed * delta
for node in get_children():
node.rotation.y += -rotation_speed * delta
i also tried setting extra cull margin from 0 to 1 as well as setting “ignore occlusion culling“ to true. but it persists, i really don’t think it’s a graphics issue as when i jump on one of the platforms while they’re flashing, the player character flashes too. the flashing is more like really fast teleporting.
Ok, so are you creating the platforms in the editor or in the code, because your code indicates that you are doing both, and recreating the platforms if they disappear?
the “platform carousel“ scene has 4 platforms that are added in the editor, but the properties of these platforms can be changed for each carousel. the platform_count property affects how many platforms a specific carousel has and if it’s less than 4, it deletes the ones it has by default until it has the specified number.
now that i type it out like this it might be a better idea to just create them in the code as well.
oh yeah ok that did it, huh.
anyways thank you a million times for your patience and wisdom!
semi-finalized code (there’s still a very minor visual bug but given that reloading the scene fixes it, it seems like an easy peasy fix once i implement separate levels):
extends Node3D
@export var rotation_speed = 1
@export var platform_size = 1
@export var platform_count = 4
@export var platform_distance = 3
const platform = "res://internal scenes/carousel_platform.tscn"
func _ready() -> void:
for i in platform_count:
var p = preload(platform).instantiate()
p.scale.x = platform_size
p.scale.z = platform_size
if i == 0:
p.position.x = platform_distance
elif i ==1:
p.position.x = -platform_distance
elif i ==2:
p.position.z = platform_distance
elif i==3:
p.position.z = -platform_distance
add_child(p)
func _process(delta: float) -> void:
rotation.y += rotation_speed * delta
for node in get_children():
node.rotation.y += -rotation_speed * delta