![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | mdswamp |
Im using Godot v2.1.5, im trying to make a simple fighting game (dont mean i used swords and guns, characters use punch, so ive created multiple shapes and sprites for punching), area2D does not work as i expected, after several days of struggling, I found that if i hit R/T button which are used for punching, when i press the key and hold it and go to the opponent, opponent area2D feels the punch and print it in output. but i didnt find any thing to solve this, it seems this engine design for simple collision (i mean when a shape entering or crossing from border of another shape), ik im a beginner in coding, specially in developing game, but i dont understand why a simple task should be so hard to put it in game…
extends KinematicBody2D
const speed = 600
var velocity = Vector2()
onready var sprite0 = get_node("Idle")
onready var sprite1 = get_node("RightFist")
onready var sprite2 = get_node("LeftFist")
onready var sprite3 = get_node("Hurt")
onready var shape0 = get_node("IdleShape")
onready var shape1 = get_node("RightFistShape")
onready var shape2 = get_node("LeftFistShape")
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
velocity = Vector2()
if Input.is_key_pressed(KEY_PERIOD):
sprite1.show()
shape1.set_trigger ( false )
sprite0.hide()
sprite2.hide()
sprite3.hide()
shape0.set_trigger ( true )
shape2.set_trigger ( true )
elif Input.is_key_pressed(KEY_COLON):
sprite2.show()
shape2.set_trigger ( false )
sprite0.hide()
sprite1.hide()
sprite3.hide()
shape0.set_trigger ( true )
shape1.set_trigger ( true )
else:
sprite0.show()
shape0.set_trigger ( false )
sprite1.hide()
sprite2.hide()
sprite3.hide()
shape1.set_trigger ( true )
shape2.set_trigger ( true )
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
var motion = move(velocity * delta)
if (is_colliding()):
var n = get_collision_normal()
motion = n.slide(motion)
velocity = n.slide(velocity)
move(motion)
func _on_Head02_body_enter( body ):
shape0.set_trigger ( false )
shape1.set_trigger ( true )
shape2.set_trigger ( true )
if (Input.is_key_pressed(KEY_PERIOD) || Input.is_key_pressed(KEY_COLON)):
print(get_name())
Maybe all you need is some time management coding - add a timer to the punch so that it will work only in certain amount of time and after that even if you detect collision, You will simply ignore it, because punch timed out.
kozaluss | 2018-09-03 15:49
Making games is hard and fighting games are particularly hard, so be patient and try to develop a state system to simplify your logic as some recommended.
Using nodes may not be the best either but since you are starting, try to keep your mechanics simple until you get more experience to use better methods (like shape casting).
eons | 2018-09-04 09:56