Search
How to apply a shader to a sprite without it becoming a rectangle?
I have been looking for a 2D reflective water shader for some time and was delighted to see that this tutorial was posted on YouTube to create just that:
https://www.youtube.com/watch?v=wPr5PvSgxFo
I've had a go at implementing it and have got the reflective water rendering. It's very "Kingdom: Two Crowns" like when spread across the full width of the scene.
However, as you can see from the image above, I've drawn a pond (as a separate Sprite2D) and I've applied the water shader to the pond. It's done that, but draws the water as a rectangle.
Is there a way to apply this shader to the Sprite2D, but conform to the actual sprite (only the light blue), rather than as a rectangle?
Loading ab buffer using Threads
I want to implement a threaded loading component into my game. I am currently saving all my settings and other level files as bytes externally (meaning not in the res:// folders), as I want to be able to export files and send them to others, so they can use them as well. There is the ResourceLoader.load_threaded_request() method, but that only returns Resources and not PackedByteArrays. As far as I can tell, there is only the FileAccess.get_file_as_bytes() method for importing byte files, which has to run in the main thread (and thus blocking it until the load is complete). Does someone know if I am missing some method here?
EDIT: I have put my fix for this into the comments
Fixed projectiles get stuck in one direction while holding back movement
Solution: I removed the else statement from the integrated_forces process and left the two lines from the condition within the process and it fixed it :)
Before:
func _integrate_forces(state): if Input.is_action_pressed("move_up"): state.apply_force(thrust.rotated(rotation)) if Input.is_action_pressed("strafe_left"): state.apply_force(thrust.rotated(rotation + 4.712)) if Input.is_action_pressed("strafe_right"): state.apply_force(thrust.rotated(rotation + 1.5708)) if Input.is_action_pressed("move_down"): state.apply_force((thrust.rotated(rotation) * -1)) else: state.apply_force(Vector2()) Globals.player_rotation = rotation
After:
func _integrate_forces(state): if Input.is_action_pressed("move_up"): state.apply_force(thrust.rotated(rotation)) if Input.is_action_pressed("strafe_left"): state.apply_force(thrust.rotated(rotation + 4.712)) if Input.is_action_pressed("strafe_right"): state.apply_force(thrust.rotated(rotation + 1.5708)) if Input.is_action_pressed("move_down"): state.apply_force((thrust.rotated(rotation) * -1)) state.apply_force(Vector2()) Globals.player_rotation = rotation
Hey guys, making some progress on this game but having a weird issue and I can't figure out what's happening. I'm instancing a ship scene into the level scene based on player selection. Weapon projectile instancing happens in the level scene. Fixed weapons shoot straight forward and this works fine as I'm moving and rotating until I hold the key to move backward, then all of the shots continue firing in the same direction I was facing when I started holding the key. Video example. This was all working fine prior to instancing the player into the scene. Here's the code I'm working with (please disregard the messy code lol).
level.gd: ``` extends Node2D class_name LevelParent
var selected_ship = Globals.player_selected_ship var format_ship_resource_path = "res://scenes/ships/ship_%s.tscn" var ship_resource_path = format_ship_resource_path % selected_ship
var laser_scene: PackedScene = preload("res://scenes/weapons/laser.tscn")
func _ready(): var ship_scene = load(ship_resource_path) var ship = ship_scene.instantiate() $Player.add_child(ship) ship.connect("shoot_fixed_weapon", _shoot_fixed_weapon) ship.connect("shoot_gimbal_weapon", _shoot_gimbal_weapon)
func _shoot_gimbal_weapon(pos,direction): var laser = laser_scene.instantiate() as Area2D laser.position = pos laser.rotation_degrees = rad_to_deg(direction.angle()) + 90 laser.direction = direction $Projectiles.add_child(laser)
func _shoot_fixed_weapon(pos, direction): var laser = laser_scene.instantiate() as Area2D laser.position = pos laser.rotation_degrees = rad_to_deg(Globals.player_rotation) Globals.fixed_hardpoint_direction = Vector2(cos(Globals.player_rotation),sin(Globals.player_rotation)) laser.direction = Globals.fixed_hardpoint_direction.rotated(-1.5708) $Projectiles.add_child(laser) ```
ship_crescent.gd:
``` extends ShipTemplate
var can_boost: bool = true
#Weapons variables var can_shoot: bool = true #hardpoint type should use 0=fixed, 1=gimbal, 2=turret #later add ability to have mixed hardpoints var hardpoint_type: int = 0
#Signals signal shoot_gimbal_weapon(pos,direction) signal shoot_fixed_weapon(pos,direction)
func _ready(): Globals.boost_max = boost_max
func _process(delta): Globals.player_pos = global_position #Build out section to target planetary bodies/NPCs/etc for auto routing if Input.is_action_just_pressed("get_cords"): print(str(Globals.player_pos)) #weapon aiming toggle, remove later after hardpoints developed if Input.is_action_just_pressed("gimbal_toggle"): if hardpoint_type == 0: hardpoint_type += 1 else: hardpoint_type -= 1
if can_boost == false: _boost_recharge(boost_regen*delta) print("boost max: " + str(boost_max)) print("boost regen: " + str(boost_regen)) print("global boost level: " + str(Globals.boost_level)) if Globals.boost_level == boost_max: can_boost = true print("can boost: Boost recharged!") ### WEAPONS ### #Remove LaserTimer when weapon modules are set up
#Fixed weapon code var player_direction = (Globals.player_pos - $FixedHardpointDirection.position).normalized() if Input.is_action_just_pressed("fire_primary") and can_shoot and Globals.laser_ammo > 0 and hardpoint_type == 0: Globals.laser_ammo -= 1 var hardpoint_positions = $HardpointPositions.get_children() can_shoot = false $Timers/LaserTimer.start() for i in hardpoint_positions: print("ship shot fired") shoot_fixed_weapon.emit(i.global_position, player_direction) #Gimbal weapon code var gimbal_direction = (get_global_mouse_position() - position).normalized() if Input.is_action_just_pressed("fire_primary") and can_shoot and Globals.laser_ammo > 0 and hardpoint_type == 1: Globals.laser_ammo -= 1 var hardpoint_positions = $HardpointPositions.get_children() can_shoot = false $Timers/LaserTimer.start() for i in hardpoint_positions: shoot_gimbal_weapon.emit(i.global_position, gimbal_direction) #Add turret (auto aim system) later
#Spaceflight physics based controls func _integrate_forces(state): if Input.is_action_pressed("move_up"): state.apply_force(thrust.rotated(rotation)) if Input.is_action_pressed("strafe_left"): state.apply_force(thrust.rotated(rotation + 4.712)) if Input.is_action_pressed("strafe_right"): state.apply_force(thrust.rotated(rotation + 1.5708)) if Input.is_action_pressed("move_down"): state.apply_force((thrust.rotated(rotation) * -1)) else: state.apply_force(Vector2()) Globals.player_rotation = rotation #REWORK boost mechanic. button hold (gradual) vs press (instant), increase cooldown, adjust boost length, add fuel/special requirements for use if Input.is_action_just_pressed("boost") and can_boost: can_boost = false Globals.boost_level = 0 #$Timers/BoostRecharge.start() state.apply_impulse((thrust.rotated(rotation) * 2)) var rotation_direction = 0 if Input.is_action_pressed("turn_right"): rotation_direction += 1 if Input.is_action_pressed("turn_left"): rotation_direction -= 1 state.apply_torque(rotation_direction * torque)
#modify later to remove globals. Base boost data on ship equipment func _boost_recharge(recharge_rate): Globals.boost_level = clamp(Globals.boost_level + recharge_rate, 0, boost_max) print(Globals.boost_level)
#Timer timeout functions func _on_boost_timer_timeout(): print("boost depleted")
func _on_boost_recharge_timeout(): print("boost timer recharged!") can_boost = true
func _on_laser_timer_timeout(): can_shoot = true ```
Persistent variables in tool script
My script sets this value in editor. How can I keep the the changes when saving the scene?
``` class Anchor: var offset: Vector3 var connected: Node3D var end: bool
var anchors: Array[Anchor]
I found [this issue](https://github.com/godotengine/godot/issues/21900), so I tried fiddling with
_get_property_list()```, but that didn't work. It also doesn't seem that I can export the var.
Thanks
Why is _ready() being triggered before the splash end?
I am trying out Godot and I've noticed that when I export the game to linux, the result has a much longer boot time
I'm talking about an 80mb executable for a 3d game and the difference between windows and linux is 0.x seconds vs 10 seconds (the windows computer is more powerful but not by that much...)
I wouldn't care much about that, but during that load time the scene's ready() is triggered and music is played. This causes the cutscene to be desynced with the music and is quite jarring.
Does anyone know why this is happening? Version is 4.1.1 btw
EDIT: after some trial and error I've finallly found the issue. Surprisingly the cause of it was the world environment, more specifically the sky settings, which I had set to high. Bumping them down pretty much fixed the issue.
It's probably a bug, but hey, it works now 🤷
Is there a way to export image files as is? Can't load them as textures on an exported project
My game has options for player customization, it's a number of .png files that are not loaded with the game startup, save for the default ones. Instead, if the player clicks a button, it will load the next file for that part (like, say, hair-2.png
)
This works fine on the editor, but I've just tested an exported version and it doesn't work there, completely failing to find any files within the .pck. If I move the executable back to the project's folder, it works as expected.
Trying to figure out the why, I've also exported via Export ZIP/PCK
, and found out it doesn't actually export any of the .png files, it only exports the .import
files. The actual images are stored in the .godot/imported
folder, each with a long, random(?) string attached to their name: hair-1.png
becomes hair-1.png-t3g9r2he7783y9hut.tcex
I haven't figured out a way to export the .png files as is, so what are my options here? Besides coupling all of the parts in a single image and separating it by frames of animation, which will require both code and art rework
Tested on both Godot 4.1.1 and 4.1.2-RC1
Help requested: Screenshot taken but disabled buttons still visible
Hi everyone, I was hoping someone could help me with the following. I have a button that saves a screenshot PNG to the Downloads folder when you press it.
What I want is for the button to disappear after it is pressed, so the screenshot does not include the two menu buttons called "%SaveReport" and "%BackMainMenu".
The code for the save button is listed below:
`
func _on_SaveReport_pressed():
$"%SaveReport".visible = false
$"%BackMainMenu".visible = false
print("I've disabled the buttons") print("That means the screenshot SHOULD be button free")
take_screenshot()
$"%SaveReport".visible = true $"%BackMainMenu".visible = true
`
As you can see, it calls the take_screenshot() function which is listed above:
`
func take_screenshot(): image = get_viewport().get_texture().get_image()
if OS.get_name() == "Web" or OS.has_feature('JavaScript'): print("We're on the web") # We're on the web
image.clear_mipmaps()
var buffer = image.save_png_to_buffer() JavaScriptBridge.download_buffer(buffer, fileName)
if OS.get_name() != "Web" or !OS.has_feature('JavaScript'): # We're not on the web print("We're not on the web")
var docs = OS.get_environment("HOME") + "/Documents"
var title = str(docs + "/results",global_ints.observed_person_name, global_ints.observation_minutes,".png")
print(title)
var _saveimage = image.save_png(title)
if OS.get_name() != "OSX": print("We're not on MacOS") var _openfolder = OS.shell_open(docs)
if OS.get_name() == "OSX": print("We're on MacOS")
var _openfolder = OS.shell_open("file://" + docs)
`
The code works. The screenshot is taken and it's saved to the Downloads folder and MacOS/Windows/Linux open up the Downloads folder straight after.
For the life of me, I can't figure out why the Back & Screenshot buttons ( "%SaveReport" and "%BackMainMenu") that I turn invisible BEFORE I call take_screenshot() end up being in the screenshot. Every single time.
Anyone have any ideas?
Thank you!
Can someone help with fixing a Godot 3.4 plugin for Godot 4.1?
Hi everyone,
Pretty much as I described in my toot (text copied here). Is anyone aware of what I may need to fix to get this plugin to work again?
I'm hoping someone can help me with a Godot engine question. With the Q&A forum being read-only, I'm hoping Lemmy people can answer this one for me.
I'm trying to use this plugin for HTML5 downloads in Godot 4.1:
https://github.com/Pukkah/HTML5-File-Exchange-for-Godot
It's for Godot 3.4, but I've upgraded my projects and want to stay in 4.1.
Currently, it throws an error “Identifier JavaScript not defined in scope” (see screenshot).
Would anyone have an idea on what to fix here? Thanks!
Can't join the Godot discord
I tried first going through the community page on the Godot website, but I keep getting the message that I couldn't accept the invite. Anyone know why that is and how I can get in?
Edit: After joining and speaking with their mod team, it seems it was just discord being discord and not anything specific to the Godot discord.