- Edited
Hi everyone.
How can I implement in Godot a custom camera confiner 2D (similar to what we have in Unity) ?
Here is an example of what i'm talking about :
(Look at the video from 7:48 to 10:30)
Hi everyone.
How can I implement in Godot a custom camera confiner 2D (similar to what we have in Unity) ?
Here is an example of what i'm talking about :
(Look at the video from 7:48 to 10:30)
Yeah exactly ! And I haven't noticed any changes in the behaviour of my game.
I've found the problem. In the editor settings, i've checked a checkbox called "save on focus lost", and after googling a lot, i've found the issue. So i've nchecked it and now everything is fine.
What is worrying though is that this problem is still persisting (it has been discovered in Godot 4.0)
Does anyone know why this error message is ?
Parent node is busy setting up children, add_child()
failed. Consider using add_child.call_deferred(child)
instead.
scene/main/window.cpp:1658 - Condition "!is_inside_tree()" is true.
I have finally achieved completing swimming movement :
class_name WaterState
extends PlayerMovementState
var input_direction := Vector2.ZERO
var is_swimming_fast := false
var exit_water := false
func enter():
if player.facing_direction == -1:
player.flip_controller(1)
player.sprite.scale.x = -1
elif player.facing_direction == 1:
player.flip_controller(1)
player.sprite.scale.x = 1
func update(_delta):
if player.is_on_surface && (INPUT.JUMP || is_swimming_fast):
switch_state("JumpPlayerState")
set_swim_facing_direction(player.swim_facing_dir)
func physics_update(delta):
set_anims()
player.handle_surface(delta)
set_input_normalized(delta)
func exit():
player.sprite.rotation = 0.0
player.sprite.scale.x = 1
is_swimming_fast = false
exit_water = true
func set_swim_facing_direction(input: float) -> void:
if input > 0 && player.velocity.x < 0:
player.swim_facing_dir *= -1
elif input < 0 && player.velocity.x > 0:
player.swim_facing_dir *= -1
func set_anims():
if (player.is_on_surface || player.can_jump_out_of_water()) && INPUT.X == 0:
play_anim("swim_surf_idle")
elif (player.is_on_surface || player.can_jump_out_of_water()) && INPUT.X != 0:
play_anim("swim_surf")
elif player.is_in_water() && INPUT.X == 0:
play_anim("swim_idle")
elif player.is_in_water() && INPUT.X != 0:
play_anim("swim")
func set_input_normalized(delta : float):
input_direction = Vector2(Input.get_axis("run_l", "run_r"), Input.get_axis("climb", "crouch")).normalized()
if input_direction.x > 0:
input_direction.x = 1
elif input_direction.x < 0:
input_direction.x = -1
if input_direction.length() > 0:
var angle = input_direction.angle() + deg_to_rad(90.0)
if !(player.is_on_surface || player.can_jump_out_of_water()):
player.sprite.rotation = lerp_angle(player.sprite.rotation, angle, 0.1)
if input_direction.length_squared() >= 1 and !is_input_direction_equal_agent_direction(input_direction.x):
player.sprite.scale.x = player.swim_facing_dir
else:
player.sprite.scale.x = player.swim_facing_dir
player.sprite.rotation = lerp_angle(player.sprite.rotation, 0.0, 0.4)
set_swim_velocity(delta)
else:
player.velocity = lerp(Vector2.ZERO, player.velocity, pow(2, -player.data.swim_control * delta))
func set_swim_velocity(delta : float):
if player.is_on_surface || player.can_jump_out_of_water():
player.apply_horizontal_velocity(player.data.swim_speed, delta)
if INPUT.Y >= 0:
player.reset_vertical_velocity()
elif INPUT.Y < 0:
player.velocity = lerp(player.velocity, input_direction * Data.swim_speed, Data.swim_accel * delta)
elif player.is_in_water():
if INPUT.SPRINT:
is_swimming_fast = true
player.velocity = lerp(player.velocity, input_direction * Data.swim_speed * 2, Data.swim_accel * delta)
elif !INPUT.SPRINT || INPUT.SPRINT_END:
is_swimming_fast = false
player.velocity = lerp(player.velocity, input_direction * Data.swim_speed, Data.swim_accel * delta)
func is_input_direction_equal_agent_direction(x_input_dir) -> bool:
##Check if player is currently facing input direction
if x_input_dir == player.sprite.scale.x:
return true
else:
return false
Hello everyone. i'm currently working on 2d platformer game in which i've implemented a hierarchical state machine.
To handle my animations, i'm using an animation player combined with a animation tree.
As my animation tree gets more complex, i want to group my animations in state machines.
For instance, one state mahine for ground animations, one state machines for in air anims, one state machine for wall anims, etc...
I need it to create concurrent state machines, very useful for implementing power-ups animations
My issue though is that i do not know how can i exit from a currently playing anim, then the state machine in which the anim is through the code, enter a new one and play the animations inside
The architecture of my state machine in the scene is that all of my state nodes are child of a unique state machine node, on which a state machine script is attached to.
Can someone help me please ?
Thanks ! As a matter of fact, I've found a way to bypass mi issue, so this post is not useful anymore.
Thank you for your attention !
trizZzle
Sorry i haven't noticed that you can't make images bigger ! Sorry ...
I'm trying to implement a sub state machine in my animation tree. I want to trigger the animation inside, but it is always failing
Can you help me please ?
Also, is my code good or not ?
FreakyGoose
OK, i'm gonna try it
FreakyGoose
Here it is :
FreakyGoose
I've currently imlemented the code you've shown and it works quite well, but i've an issue.
When i'm swimming upward or downward, without applying any horizontal input the sprite disappears. Can you help me please ?
I also would like to make a multiplayer fps shooter, with simplicity in mind, but with a solid, rugged, and dynamic gameplay, with a huge consideration to environments, in a very low-poly style.
My dream game would be an aviation combat game, with very strong focus on characters and their stories like Top Gun Maverick, high-fidelity but reliable airplane physics and intense and more realistics dogfights, in an 3d open world environment.
My goal is to make an interesting game, captivating the player, and not boring like Ace combat 7 in some aspects
Megalomaniak
Ok. Thank you for your piece of advice
How can I detect water surface effectively ?
FreakyGoose
Thanks !
Toxe
I'm currently using a hierarchical state machine
Here is the code and the result :
Thanks, i'm going to try this and i'll tell you if it works !
Hi everyone ! I'm currently working on a 2d game and i would like to add a swimming logic similar to the one found in Ori and the will of the wisps. But i encounter big issues about flipping the character in water and orient the player upward while swimming in opposite direction. I've recorded what i want to achieve :
Can you help me please ?