@animax940 said:
Thank you so much :)
it works now very well you are amazing bro
I'm glad I came here and I wish to be like you one day
but until then I will need more help in the future :frown:
Awesome! I'm glad the code works.
As for being like me, I am honored. I've been programming and doing game development for years, and I can safely say that all my experience has come from lots of learning, experimenting, and receiving help from others.
There is nothing wrong with needing help! You cannot know what you don't know. Helping others is part of what the community here is for. I still need help and struggle too, I just generally don't post about it online and instead ask friends for ideas/help.
As far as the collision shape changing, to be honest I'm not sure what the best method would be. The example I gave basically just turns CollisionShape nodes on/off based on the animation used. To integrate it into the main script, you just need to slightly change the _process_animation function:
func _process_animation():
if is_on_floor():
# Play the jump animation if jump was just pressed
if input_vector.y > 0.75:
$Sprite.play("Jump")
# Run when on the floor and the input is over 0.75 in either direction:
elif input_vector.x < -0.75 or input_vector.x > 0.75:
$Sprite.play("Run")
else:
$Sprite.play("Idle")
else:
# Play the jump animation if the character is moving up
if motion.y < 0
$Sprite.play("Jump")
elif motion.y > 0
$Sprite.play("Fall")
# (Potentially) change the collision shape
_process_animation_collision_shape()
# Some class variables we'll need. We'll assume the default/initial collision shape
# node is named "CollisionShape_Standing"
var current_collision_shape = $CollisionShape_Standing
# Note: for this to work, all of the other collision shapes except
# "CollisionShape_Standing" will need to be disabled initially in the player scene.
func _process_animation_collision_shape():
# If the jump/fall animation is playing...
if $Sprite.animation == "Jump" or $Sprite.animation == "Fall":
# Enable the CollisionShape node for jumping/falling.
current_collision_shape.disabled = true
current_collision_shape = $CollisionShape_InAir
current_collision_shape.disabled = false
# If the slide animation is playing...
elif $Sprite.animation == "Slide":
# Enable the CollisionShape node for sliding.
current_collision_shape.disabled = true
current_collision_shape = $CollisionShape_Sliding
current_collision_shape.disabled = false
# If the current animation does not have a specific collision shape, then use
# the default/initial collision shape
else:
current_collision_shape.disabled = true
current_collision_shape = $CollisionShape_Standing
current_collision_shape.disabled = false
Or something like that. It primarily requires that you know the names of the CollisionShape nodes to use for the player states, and that all of the CollisionShape nodes but the initial CollisionShape have the disabled property set to true.
Though as I said, I do not know what the best method/solution would be.
As for adding additional animations, like animations that play when the character attacks, it really depends on how the rest of the code for attacking works. If you are using a boolean to track whether the player is attacking, then you just need to check if the attack boolean is true as the first if statement in the conditionals within the air. For example:
func _process_animation():
if is_on_floor():
# Play the jump animation if jump was just pressed
if input_vector.y > 0.75:
$Sprite.play("Jump")
# Run when on the floor and the input is over 0.75 in either direction:
elif input_vector.x < -0.75 or input_vector.x > 0.75:
$Sprite.play("Run")
else:
$Sprite.play("Idle")
else:
# Play the attack animation is the player is attacking in the air
if is_attacking == true:
$Sprite.play("InAir_Attack")
# Play the jump animation if the character is moving up
elif motion.y < 0
$Sprite.play("Jump")
elif motion.y > 0
$Sprite.play("Fall")
Though as I said, it really depends. You'll probably need to experiment and see what works best for you based on how your attacking system works, how the animation works, and the complexity of the code.
Hopefully this helps!