- Edited
Hi alls, i am new here and new in Godot. Vew weeks ago, i started to learn Godot with V 2.1...and now i switched to V 3.0. For me its hard to feature out the differences, at least, the is_colliding doesnt exist in V 3.0. in my vertical scroller game i only move the player on x axis via animations (for fixed x coodrinates). the goforward effect i realise by scrolling the backgrounds down.
Can you help me to detect a collision to a nonplayer object?
For better understanding, here is my code:
#Vertical scroller game with moving backgrounds.
#Player only moving on x axis via Animations to fixed x-coordinates
#by pressing keyboard left or right,
#or by pressing buttons (for Android version).
#the "go forward" effect is getting by scrolling the backgrounds and all nonplayer objects.
#The Player has three lines where he can "move" to: left, middle and right
#backgrounds: simple sprites
#player: Sprite -> KinematicBody2D -> CollisionShape2D
#nonplayer (one object, parented on background01): Sprite -> StaticBody2D -> CollisionShape2D
#extends Node2D # main node of gamescene with Backgrounds, Player, Buttons and Playeranimation
var sp_BG1 # Background 01
var sp_BG2 # Background 02
var a_Player # Player Animations = ML (middle to left), LM (left to middle), MR (middle to right) and RM (right to middle)
var line = "middle" # actual line = left, middle and right
var animating = "ready" # is Animation activ? = ready and run
export (float) var bgspeed # vertical scroll speed of Background (and nonPlayer objects)
func _ready(): # define nodes (get_node)
sp_BG1 = $sp_BG1
sp_BG2 = $sp_BG2
a_Player = $a_Player
func _input(event): # PC keys
if(Input.is_action_just_pressed("ui_left") && animating == "ready"):
if(line == "middle"):
a_Player.play("a_ML")
line = "left"
if(line == "right"):
a_Player.play("a_RM")
line = "middle"
if(Input.is_action_just_pressed("ui_right") && animating == "ready"):
if(line == "middle"):
a_Player.play("a_MR")
line = "right"
if(line == "left"):
a_Player.play("a_LM")
line = "middle"
func _process(delta):
if (sp_BG1.position.y <= 1334+667): # Background01 scrolls out of scene
sp_BG1.translate(Vector2(0,bgspeed))
else:
sp_BG1.position.y = -667 # Background01 set top of scene
if (sp_BG2.position.y <= 1334+667): # Background scrolls out of scene
sp_BG2.translate(Vector2(0,bgspeed))
else:
sp_BG2.position.y = -667 # Background set top of scene
func _on_a_Player_animation_started( name ): # Playeranimation is running
animating = "runs"
func _on_a_Player_animation_finished( name ): # Playeranimation is not running
animating = "ready"
func _on_b_left_pressed(): # button for Playermoving left via Animation (for Android), similar to PC keys
if(line == "middle" && animating == "ready"):
a_Player.play("a_ML")
line = "left"
if(line == "right" && animating == "ready"):
a_Player.play("a_RM")
line = "middle"
func _on_b_right_pressed(): # button for Playermoving right via Animation (for Android), similar to PC keys
if(line == "middle" && animating == "ready"):
a_Player.play("a_MR")
line = "right"
if(line == "left" && animating == "ready"):
a_Player.play("a_LM")
line = "middle"
...i hope its ok, how i ask my quest and you understand me...if not, dont hasistate to ask me. Oh...and sorry for my bad english!
Nice Day Neo
lol...hard to format right in here xD