Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ddarkmoto | |
Old Version | Published before Godot 3 was released. |
Hello everyone.
I have multiple instances of a RigidBody2D (char.tscn), and I want them to NOT COLLIDE each other. I tried getting the variable(enemygen) of an instanced scene and passed it to another scene (char.gd) as an argument for the PS2D.body_add_collision_exception. The problem was, sometimes it works and sometimes, it doesn’t.
Below is the image and the source code for reference. Thank you in advance.
extends RigidBody2D
var WALK_ACCEL = 200
var WALK_DEACCEL = 300
var MAX_WALK_ACCEL = 300
var get_last_move
var floor_h_velocity = 0.0
var node2d
var bump
func _integrate_forces(s):
var move = s.get_linear_velocity()
var step = s.get_step()
var old_bul = node2d.get("enemygen").get_rid()
move.x -= floor_h_velocity
floor_h_velocity = 0.0
var found_floor = false
var floor_index = -1
for x in range(s.get_contact_count()):
var ci = s.get_contact_local_normal(x)
#print ("ci: "+str(ci))
if (ci.dot(Vector2(0, -1)) > 0.6):
#print ("ci.dot: "+str(ci.dot(Vector2(0, -1))))
found_floor = true
floor_index = x
PS2D.body_add_collision_exception(old_bul, get_rid())
if (get_node("right").is_colliding()):
get_node("right").set_enabled(false)
get_node("left").set_enabled(true)
bump = "bump"
#print ("colliding")
#print (bump)
if (get_node("left").is_colliding()):
get_node("left").set_enabled(false)
get_node("right").set_enabled(true)
bump = "bump"
if (bump == "bump"):
if (get_node("Sprite").is_flipped_h()):
get_node("Sprite").set_flip_h(false)
bump = ""
else:
get_node("Sprite").set_flip_h(true)
bump = ""
if (found_floor):
if (get_node("Sprite").is_flipped_h()):
move.x -= WALK_ACCEL*step
#print ("x: "+str(move.x))
else:
move.x += WALK_ACCEL*step
#print ("x: "+str(move.x))
s.set_linear_velocity(move)
get_last_move = move.x
func _ready():
node2d = get_node("/root/world")