0 votes

I've made an Scene called WorldBlock, which will be the basis for a series of blocks with common behaviour. This Scene structure is simply a RigidBody2D with the following attached script:

extends Node2D

enum BlockMaterial {
    Wood,
    Metal,
}

export (BlockMaterial) var blockMaterial
export (int) var initialResistance

signal damage

Now, I want to create a block based on this one. I created a block called Bomb, and the strucure is as follows:

- Link to WorldBlock
    - Sprite
    - Explosion Area (Area2D)
        - Area (CircleShape2D)
    - Explosion (Particles2D)
    - CollisionShape2D
    - Countdown (Timer)

And the script is, currently, as follows:

 extends "res://WorldBlock.gd"

const WorldBlock = preload("res://WorldBlock.gd")

var blowing = false

func _ready():
    $Countdown.connect("timeout", self, "_blow")
    connect("damage", self, "_blow")

func _blow():
    if blowing:
        return

    blowing = true

    $Sprite.hide()
    $CollisionShape2D.queue_free()
    $Explosion.emitting = true

    $Countdown.disconnect("timeout", self, "_blow")
    $Countdown.connect("timeout", self, "queue_free")
    $Countdown.wait_time = 2
    $Countdown.start()

    var within = $ExplosionArea.get_overlapping_bodies()

    for item in within:
        if item is WorldBlock and item != self:
            item.emit_signal("damage")

func _integrate_forces(state):
    set_applied_force(Vector2(1.0, 0.0))

However, I get the following error: error(26,38): Method 'set_applied_force' is not declared in the current class.

Why I get this if WorldBlock is a RigidBody2D? How can I apply the force within my block?

in Engine by (17 points)

1 Answer

+1 vote
Best answer

your first script does not extend RigidBody2D but extends Node2D changing that will most likely fix your error

by (366 points)
selected by

Well, I didn't notice that. Why does Godot allow for a script to extend a class different of what it is? Does this makes sense in any scenario?

Not sure if it makes sense to do so, my guess was just that you changed nodetype after creating the script

It can be really useful. See this KCC tutorial for an example.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.