0 votes

i try to create a simple fighting game (between player1 and player2)
i'm using multiple sprites and collision polygons in each player node for showing strike.
but there is a big problem in collision, no matter what i've done, it didn't work properly.
right fist "collision" works when i press hitting button and moving button together (i mean i should go to the opponent and then use hit button), on the other hand left fist "collision" works sometimes and does not work the other time. beside it seems fists are felt just when they collide with head's area2d from sides and there is no collision it hits straight to the forehead. it seems that there is something fundamentally wrong with collision shape in general or i need better coding skill... what should i do? thanks in advance

P.S: moving, changing sprites after hitting action buttons work fine, collision is the problem here. i change collisionpolygons several times, even change them to collisionshape with no success...

this my node tree for player1:
*Player01 (KinematicBody2D)

Idle (Sprite1)
LeftFist (Sprite2)
RightFist (Sprite3)
IdleShape (CollisionPolygon2D)
RightFistShape (CollisionPolygon2D)
LeftFistShape (CollisionPolygon2D)
Head01 (Area2D)

and this is my script code for player1:

extends KinematicBody2D

const speed = 600
var velocity = Vector2()
onready var sprite10 = get_node("Idle")
onready var sprite11 = get_node("RightFist")
onready var sprite12 = get_node("LeftFist")
onready var sprite13 = get_node("Hurt")
onready var shape10 = get_node("IdleShape")
onready var shape11 = get_node("RightFistShape")
onready var shape12 = get_node("LeftFistShape")

func _ready():

func _fixed_process(delta):
     velocity = Vector2()

     if Input.is_action_pressed("ui_right"):
        velocity.x += 1
     if Input.is_action_pressed("ui_left"):
        velocity.x -= 1
     if Input.is_action_pressed("ui_down"):
        velocity.y += 1
     if Input.is_action_pressed("ui_up"):
        velocity.y -= 1
     if velocity.length() > 0:
        velocity = velocity.normalized() * speed

     if Input.is_key_pressed(KEY_PERIOD):
        shape11.set_trigger ( false )
        shape12.set_trigger ( true )

     elif Input.is_key_pressed(KEY_COLON):
        shape12.set_trigger ( false )
        shape11.set_trigger ( true )

        shape11.set_trigger ( true )
        shape12.set_trigger ( true )

     var motion = move(velocity * delta)
     if (is_colliding()):
        var n = get_collision_normal()
        motion = n.slide(motion)
        velocity = n.slide(velocity)

func _on_Head02_body_enter( body ):
     if (Input.is_key_pressed(KEY_PERIOD) || Input.is_key_pressed(KEY_COLON)):
        print ("Shape 10 state: ", shape10.is_trigger())
        print ("Shape 11 state:", shape11.is_trigger())
        print ("Shape 12 state:", shape12.is_trigger())
        shape11.set_trigger ( true )
        shape12.set_trigger ( true )
in Engine by (76 points)

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.