![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Schwein |
![]() |
Old Version | Published before Godot 3 was released. |
Hello, I’m trying to create a collision effect between the player and a wall, but I do not know what to do. Could someone help me?
principal = main (the game world), personagem = character (the player)
player.gd:
extends Area2D
var vel = 200
var tempElapsed = 0
func _ready():
set_process(true)
pass
func _process(delta):
var d = 0
var e = 0
var ac = 0
var ab = 0
tempElapsed = tempElapsed + delta
if Input.is_action_pressed("left") and Input.is_action_pressed("up"):
ac = -2
if Input.is_action_pressed("right") and Input.is_action_pressed("up"):
ab = -2
if Input.is_action_pressed("left") and Input.is_action_pressed("down"):
ac = 2
if Input.is_action_pressed("right") and Input.is_action_pressed("up"):
ab = 2
if Input.is_action_pressed("left"):
e = -2
animation(5, 1)
elif Input.is_action_pressed("right"):
d = 2
animation(1, -1)
elif Input.is_action_pressed("up"):
ac = -2
animation(6, 0)
elif Input.is_action_pressed("down"):
ab = 2
animation(0, 0)
set_pos(get_pos() + Vector2((1 * vel * delta * (d + e)), (1 * vel * delta * (ac + ab))))
pass
func animation(int1, int2):
if(tempElapsed > 0.1):
if get_node("AnimatedSprite").get_frame() != int1:
get_node("AnimatedSprite").set_frame(int1)
elif get_node("AnimatedSprite").get_frame() == int1:
get_node("AnimatedSprite").set_frame(get_node("AnimatedSprite").get_frame() - int2)
tempElapsed = 0
pass
func _on_player_area_enter( area ):
if area.is_in_group("wall"):
print(true)
pass