Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | erasmo85 | |
Old Version | Published before Godot 3 was released. |
Hi everybody,
recently I started to use Godot Engine, which I like it a lot, so I dived myself completely into tutorials, demo projects and snippets. I was following the SpaceBlaster84 tut, and I got to the 11th chapter, where I decided to create the rocks dynamically, ie having just one scene to create the various rocks instead of having three with just different sizes.
My Rock scene is set like this:
Rock_root (Type: Node)
–RigidBody2D
----Sprite
----CollisionShape2D
I have this piece of code from the script of the RigidBody2D:
func setRock(size):
var circleShape = CircleShape2D.new()
if size == 1: #Large
durability = 3
points = 30
get_node("Sprite").set_texture(rockL)
circleShape.set_radius(80)
circleShape.set_custom_solver_bias(0.0)
get_node("CollisionShape2D").set_shape(circleShape)
elif size == 2: #Medium
durability = 2
points = 20
get_node("Sprite").set_texture(rockM)
get_node("Sprite").set_scale(Vector2(1.5,1.5))
circleShape.set_radius(45)
circleShape.set_custom_solver_bias(0.0)
get_node("CollisionShape2D").set_shape(circleShape)
get_node("CollisionShape2D").set_pos(Vector2(4,-0.5))
elif size == 3: #Small
durability = 1
points = 10
get_node("Sprite").set_texture(rockS)
get_node("Sprite").set_scale(Vector2(1.5,1.5))
circleShape.set_radius(23)
circleShape.set_custom_solver_bias(0.0)
get_node("CollisionShape2D").set_shape(circleShape)
which works just fine with the images but doesn’t with the collisions.
Setting the shape (say, a circle one) for the CollisionShape2D element works fine, but what if I want a rectangular shape or anything?
So the question is: how can I make the collision (or the shape, or whatever) work in order to… destroy those pesky rocks (or let the rocks destroy the ship)?
Thanks in advance for the help!
Format correctly the code snippet would help readability. Please use the { } icon with the selected code piece. Thanks
genete | 2016-05-30 22:13
in that episode, FOS365 says “let’s put everything together”… is your script assigned to the correct node and everything? what’s the thing isn’t working for you?
shackra | 2016-05-31 05:13
Yep, the script is assigned to the RigidBody2D element, everything works fine except for the collision between the rocks and the laser or the ship.
erasmo85 | 2016-05-31 13:50