Godot Version
4.4
Question
The barrel sprite has a collision body which the character having collision body near the feet interacts with.
But, for some reason the character is also colliding with something in front of the collision body.
Sprite node hierarchy:
StaticBody2D
under that,
CollsionBody2D
Sprite2D
I had a similar problem with my wall sprite in my game.
character script(if that helps):
extends CharacterBody2D
@export var SPEED = 150.0
@export var HEALTH = 100.0
var move = true
var roll_status = true
#For aim
var rotate=0
var aim_min = -75
var aim_max = 75
func _ready():
$pivot.visible = false
func _physics_process(delta):
if Input.is_action_just_pressed(âmove_1â):
$pivot.visible = false
move = not move
if move:
velocity = Vector2.ZERO
if(Input.is_action_pressed(âleft_1â)):
velocity.x -= SPEED
if(Input.is_action_pressed(âright_1â)):
velocity.x += SPEED
if(Input.is_action_pressed(âup_1â)):
velocity.y -= SPEED
if(Input.is_action_pressed(âdown_1â)):
velocity.y += SPEED
if(Input.is_action_just_pressed(âshoot_1+roll_1â)):
roll()
if not move:
$pivot.visible = true
velocity = Vector2.ZERO
if Input.is_action_pressed(âup_1â):
rotate-=5
if Input.is_action_pressed(âdown_1â):
rotate+=5
rotate = clamp(rotate,aim_min,aim_max)
$pivot.rotation_degrees = rotate
if Input.is_action_just_pressed(âshoot_1+roll_1â):
shoot()
move_and_slide()
func shoot():
const bullet_scene = preload(âres://scenes/bullet.tscnâ)
var bullet = bullet_scene.instantiate()
get_parent().add_child(bullet)
bullet.rotate = rotate
bullet.Name = âcharacterâ
bullet.global_position = $pivot/aim.global_position
func headshot():
dead()
func bodyshot():
HEALTH-=50
if HEALTH <= 0:
dead()
func dead():
var parent = get_tree().get_current_scene()
parent.game_over(â\nPlayer 2 wonâ)
$â.â.queue_free()
func roll():
if roll_status:
SPEED+=100
$Roll.start()
roll_status = false
func _on_roll_timeout():
SPEED-=100
roll_status = true
