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)? :D
Thanks in advance for the help!