+1 vote

this my code , it can Can simulate physical fall , but not collison with StaticBody2D

extends Node2D

var vs = VisualServer
var ps = Physics2DServer
func _ready():

func create_virus():
    var body = ps.body_create()

    ps.body_set_mode(body, ps.BODY_MODE_RIGID)
    var shape = RectangleShape2D.new()
    shape.extents = Vector2(100, 100)
    ps.body_add_shape(body, shape)
    ps.body_set_space(body, get_world_2d().space)
    var xform = Transform2D().translated(Vector2(1080/2, 1920/2))
    ps.body_set_state(body, ps.BODY_STATE_TRANSFORM, xform)
    var sprite = create_item("res://icon.png")
    ps.body_set_force_integration_callback(body, self, "_body_moved", sprite)

 func create_item(path):
    var ci_rid = VisualServer.canvas_item_create()
    VisualServer.canvas_item_set_parent(ci_rid, get_canvas_item())
    var sprite = load(path)
    VisualServer.canvas_item_add_texture_rect(ci_rid, Rect2(sprite.get_size() / 2, sprite.get_size()), sprite)
    return ci_rid

func _body_moved(state, index):
    VisualServer.canvas_item_set_transform(index, state.transform)
asked May 11, 2019 in Engine by myhalibobo (24 points)

I'm in the same situation.

Did you find the cause of the problem?

Please log in or register to answer this question.

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 How to use this Q&A? before posting your first questions.