system
1
|
|
|
|
Attention |
Topic was automatically imported from the old Question2Answer platform. |
|
Asked By |
Godotuser5675 |
func move(delta): # move the player linearly
# var col_info = move_and_collide(velocity * delta)
# var remaining_vel = Vector2()
var remaining_vel = move_and_slide(velocity)
var col_info = get_slide_collision(0)
handle_collision(delta, col_info, remaining_vel, false)
func handle_collision(delta, col_info, rem_vel, slide = false):
handle_nonslide_collision(delta, col_info, rem_vel)
func handle_nonslide_collision(delta, col_info, rem_vel):
if(col_info):
var bodyHit = col_info.collider
if(col_info.collider.get_class() == "KinematicBody2D"):
if(bodyHit.is_in_group("KinematicBox")):
var bodyHitTex = bodyHit.get_node("Sprite").get_texture()
var bodyHitSprite = bodyHit.get_node("Sprite")
var Tex = $Sprite.get_texture()
# var side = Global.at_what_side(bodyHit.position, bodyHitTex.get_width() / bodyHitSprite.hframes, bodyHitTex.get_height() / bodyHitSprite.vframes, position, tileSize, tileSize)
var side = bodyHit.side_touched
match side:
"Right":
bodyHit.move_and_collide(Vector2(col_info.get_remainder().x, 0))
my_side = "Right"
"Left":
my_side = "Left"
bodyHit.move_and_collide(Vector2(col_info.get_remainder().x, 0))
"Up":
my_side = "Up"
bodyHit.move_and_collide(Vector2(0, col_info.get_remainder().y))
"Down":
my_side = "Down"
bodyHit.move_and_collide(Vector2(0, col_info.get_remainder().y))
_:
my_side = "N/A"
else:
bodyHit.move_and_collide(col_info.get_remainder())
pass
col_info = move_and_collide(col_info.get_remainder())
if(col_info):
v_length = velocity.length() - col_info.get_remainder().length()
elif(col_info.collider.get_class() == "RigidBody2D"):
col_info.collider.add_force(Vector2(), velocity * delta)
bodyHit.col = true
col_info = move_and_collide(col_info.get_remainder())
if(col_info):
v_length = velocity.length() - col_info.get_remainder().length()
else:
v_length = velocity.length()
col_info = null
pass