Godot

5885 readers
52 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

founded 1 year ago
MODERATORS
476
477
 
 

They're free to use commercially, and some of them are pretty neat if you want to show off support for the engine in your game. Preview image:

A screenshot previewing most of them

478
 
 

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!

479
 
 

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!

480
481
482
 
 

I'm trying to make something in 2d where once the player reaches the end of the level, they're back at the beginning and it just keeps going like that. I could imagine how this could be done in terms of setting the player position, but if I have a scrolling parallax background, how would I make that match up reliably?

483
484
485
486
487
 
 

I've been looking into some tutorials, mainly this one - https://www.gotut.net/custom-key-bindings-in-godot-4/

My particular problem is that this and every other tutorial of key rebind only deals with 1 action = 1 keybind, while I want my actions to have 3 keybinds: 2 from the keyboard, 1 from a controller. Because of that, I can't simply empty the InputMap of a given action and add the newly pressed key.

After quite some time thinking and testing, I've managed to cobble together this code (based on the one from the link above) that works as I want: it removes the previous keybind and adds the new one, without messing any of the previous keys.

func _input(event):
	if !current_button:
		return
	if event is InputEventKey and $keypress.visible:
		var action: String
		match current_button.name:
			"rebind_jump":
				action = "game_jump"
		#Match repeat for each button/action, also "duplicated" for each of the alternative keys/buttons, as "alt_game_jump", etc
		#The following lines happen after the match defines the action 
		rebind(event,action, current_button.text)
		current_button.text = event.as_text()
		current_button = null


## The rebind function is called by sending the event, a string of the action proper and the button's current text as the "oldkey"
## rebind(event, "game_jump", $rebind_jump.text)
## After the event call, the button's text is set like this: $rebind_jump.text = event.as_text()

func rebind(event: InputEvent, action: String, oldkey:String):
	var existing : Dictionary = {}
	var key: String
	for ia in InputMap.action_get_events(action):
		#The split(" ") below happens because physical key presses are sent as "E (Phyisical)" or "Ctrl (Physical)"
		if ia.as_text().split(" ")[0] != "Joypad":
			key = ia.as_text().split(" ")[0]
		else:
			key = ia.as_text()
		existing[key] = ia
	for acts in InputMap.get_actions():
		#Removes the key from any other events 
		InputMap.action_erase_event(acts, event)
	InputMap.action_erase_event(action, existing[oldkey])
	InputMap.action_add_event(action, event)

While it works as is for keyboard rebind, I haven't tested it with a controller, as I don't have one around to test.

But my main question is: is this "ideal"? Is there a better/easier way to do this, rebind an action substituting only one key?

EDIT: Did a few tweaks on the code. One thing that I haven't figured out yet is a way to update a key that was already bound to another button. For example: if "Ctrl" is bound to jump, and I bind it to attack, it automatically unbinds from jump. If I then try to bind anything to that specific jump button, I'll get a Invalid Index error at the InputMap.action_erase_event(action, existing[oldkey])

488
 
 

I was seeing a video on common tricks FPS games use, and one of them was having the weapon render on a higher and/or separate layer to avoid having it clip with other objects in the world. How would something like this be done in Godot?

489
 
 

Since I'm currently dealing with this problem, I'm gonna leave this info here, so anyone that comes across it knows what to do to fix it. Currently working on 4.1.1, should work on 3.x too

This is a problem that happens if you rename or delete files outside the Godot editor. Godot may warn you, or it may simply keep a cached copy and keep you completely unaware of it until you export the game and try to play it. It's always a good thing to check for these once in a while.

Related questions:

HOW TO FIX:

  • Create a dummy file, it can be a.PNG or whatever
  • Open the problematic scenes with a text editor
  • Change the path of the offending files to the dummy. They're usually at the top of the file, loaded as [ext_resource type="Texture" uid="" path=res://graphics/missing.png" id="10_0y2mn"
  • After saving, try to load the scene again. Be sure to run the Debug console version of Godot
  • If everything went well, it should open. Delete the dummy file from within the editor.

If that doesn't work, try this instead:

  • Open the problematic scenes with a text editor
  • Remove any lines that point to the offending files.
  • Run the Godot with the debug console
  • Attempt to open the scene in the editor. If it gives an error, check the debug console, the most likely error will be something like res://scenes/problemscene.tscn:3815 - Parse Error: Can't load cached ext-resource id: 10_0y2mn
  • Back in the text editor, look for that id within the scene. It'll likely be something similar to texture = ExtResource("10_0y2mn"). Delete it
  • Repeat the last 2 steps until the errors stop.
490
 
 

I'm trying to use a tween to change the position of one of the points in a line2d, but I'm not sure what the syntax would be for this.

This is what I have: tween.tween_property(line, "points", target_position, time)

Obviously this doesn't work because points has more than one point to make the line. If I need index 1 of points specifically, how would I do that? Or do I have to address it as a whole PackedVector2Array?

EDIT: I found the answer to this in case anyone else stumbles across this. You use colons, like this:

tween.tween_property(line, "points:1, target_position, time)

491
 
 

I'm making a platformer, so when the player is facing the opposite direction, I just want to mirror the graphics. I've set up a whole Skeleton2D with Bones, then set up InverseKinematics to help animate it.

The problem is that I can't find a way to make the thing work when mirrored. Scaling the target IK doesn't work. Multiplying the IK position by -1 also doesn't work properly. It does change the target bone rotation, but the bone rotates in the reverse direction (it "pushes" the bone away).

The closest I got to get it to work properly is by applying a negative scale to the affected bone after scaling the skeleton to -1, but even then, the image flips back to the right side.

Right now, I'm starting to think I'll have to use the IKs to create the animations only as the means to key the bone positions, as I can't figure out a way to make a flipped animation with IK targets. So, once all bones are keyed into the animations, I can safely delete the IKs

To reproduce:

  • Make a Skeleton2D node, make 3 children Bone2D nodes, one being the parent of the other (B1 -> B2 -> B3)
  • Create a Node2D to use as IK target
  • On the Skeleton2D Inspector, add a new SkeletonModification and enable it
  • Add a new Element to the SkeletonModification, of type TwoBoneIK (third option, from the bottom up)
  • Joint Bone One = B2 (uppermost bone); Joint Bone Two = B3 (farthest most); Target = IK_Target
  • Move the target around to see if it's working properly.
  • Attempt to mirror it in a way that it doesn't break

TLDR - How do I horizontally flip a skeleton2D with IK without breaking the animations?

492
 
 

I feel like Godot's AnimationTree is significantly more valuable and useful than Unity's Animator component. You can nest your Statemacchins or blend trees or BlendSpace2Ds. You can attach scripts to individual Statemachine Transitions if you wanted.

You also have access to the Advance Expressions, which is a fantastic way to not have to manually set a billion bools

And you can actually manipulate all of this from code, something I detested about Unity was how locked out I felt from the Animator component, and the legacy animation system is beyond old and depreciated. Godot doesn't lock anything away and you can modify everything you want from code, if you need.

Curious if maybe I missed something with my time in Unity, but it made me frustrated and annoyed more than anything.

493
494
 
 

I'm just looking for a good review of modern large-scale terrain rendering techniques. I've been reading about a few individually, various quadtree stuff, GPU clipmaps, continuous methods, but I don't have a good grasp of the state of the art, performance comparisons between methods, what I should invest my time learning better etc. A well-written review article would help a lot. But I can't find much, at least not from the last few years. If there isn't a good academic article maybe someone wrote a great blog post or something? I get a lot of hits searching around but they are mostly zillions of different people implementing this or that algorithm for demo projects, it's harder to find systematically put together information giving an overview of the field and techniques.

495
496
497
498
499
500
view more: ‹ prev next ›