Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | winniethewind |
I currently have a rigidbody set up like a collectable, which deletes itself from the scene once I trigger the collision. It uses a area-enter signals in the area trigger, and a script for the rigidbody itself. Heres the main part of my code that I’m using:
extends RigidBody
var isRotatingFaster
func _ready():
isRotatingFaster = false
func _process(delta):
if isRotatingFaster == true:
get_parent().get_node("Item1/GreenItem").rotate_y(7 * delta)
if isRotatingFaster == false:
get_parent().get_node("Item1/GreenItem").rotate_y(1 * delta)
func _on_Area_body_entered( body ):
if body is KinematicBody:
get_parent().remove_child(self)
func _on_Area1_body_entered( body ):
if body is KinematicBody:
isRotatingFaster = true
func _on_Area1_body_exited( body ):
if body is KinematicBody:
isRotatingFaster = false
If I were to duplicate the rigidbody and attach a script with the same code, it would probably work, but if I wanted 50 objects at the same time, I’d have to do exactly what I described 50 times!?!?
While I do understand for loops which is how I would normally solve this problem in a language like java, I’m unsure how to approach this problem, or if there is an alternative way to do it in godot. Basically the goal is to have 50 collectables randomly placed across the play field.
Any help would be appreciated, thanks!
You could reduce performance overhead by just using an Area2D instead of a RigidBody if you don’t need realistic physics for your collectibles. You can rotate an Area2D node.
DodoIta | 2018-03-13 10:03
Hey there thanks for commenting. My project is in 3D which I forgot to mention. The rigid is 3D. I don’t really have realistic physics so I might alter it a bit so I dont utilize something I dont need.
winniethewind | 2018-03-13 11:58