Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lavaduder | |
Old Version | Published before Godot 3 was released. |
I have two kinematic bodies ramming into each other in a scene. I want it so that if one kinematicbody detects the other, it will respond and load a script, however I can’t seem to detect the other’s presence. (Since the metadata is constantly returning zero). How does one detect collision in kinematicbody.
tool
extends KinematicBody2D
#Characteristics
export var hp = 1
export var damage = 1
#enum statuseffect {normal,damaged,cutting,poison,fire}
#var priority = 0
export var speed = 1
export var power = 1
export var defense = 1
#Movement
export var playercontroler = 0
export var vel = Vector2()
export var gravity = 0
export var agility = 1000
#Children Nodes
onready var charspr = get_node("colid/sprite")
onready var hitbox = get_node("hitbox")
#Effects
export var speedcolor = Color("07ff00")
export var powercolor = Color("ff0000")
export var defensecolor = Color("1300ff")
export var normalcolor = Color("ffffff")
func _ready():
set_fixed_process(true)
pass
func _fixed_process(delta):
#Input
var mover = Input.is_action_pressed(str(playercontroler) + "right")
var movel = Input.is_action_pressed(str(playercontroler) + "left")
var attspeed = Input.is_action_pressed(str(playercontroler) + "attackspeed")
var attpower = Input.is_action_pressed(str(playercontroler) + "attackpower")
var attdefense = Input.is_action_pressed(str(playercontroler) + "attackdefense")
#Input X axis
if (mover):#mover
vel.x = agility
elif (movel):
vel.x = -agility
else:
vel.x = 0
#Input Y axis
vel.y += gravity
#Input Attack
if (attspeed):
add_to_group("speed")
if charspr != null:
charspr.set_modulate(speedcolor)
elif (attpower):
add_to_group("power")
if charspr != null:
charspr.set_modulate(powercolor)
# add_to_group(priority)
elif (attdefense):
add_to_group("defense")
if charspr != null:
charspr.set_modulate(defensecolor)
# add_to_group(priority)
#MovePlayer
var motion = vel * delta
move(motion)
# print(vel)
#Slide player if colliding
if is_colliding():
var normal = get_collision_normal()
motion = normal.slide(motion)
vel = normal.slide(vel)
move(motion)
#Collision for hitbox
#If the metadata comes back 0 it has not collided
print(str(playercontroler)+" Collider's Metadata is: "+str(get_collider_metadata()))
pass
Metadata is empty, but did you actually got them to collide? Is if is_colliding():
becoming true
when that happens?
Zylann | 2017-04-25 18:15
Yes they are colliding, sorry I did not include that part in the statement.
lavaduder | 2017-04-26 07:51