I was having trouble too, I just used imgur because that website lets you upload images for free and put the link here
lemu_kymoh
Posts
-
-
I might have some suspicions as to why it doesn't work, but the text is hard to read. Could you please send an image of the entire screen? I want to take a look at the line spacing and also the inspector.
-
"Not declared in the current scope" simply means that the variable couldn't be found.All you need is "var timer = 0" near the top of the code. The top area of the script should look like this:
extends RichTextLabel @export var texts: PackedStringArray var current = 0 var timer = 0
-
Thankfully your error message seems to give plenty of information about it. My guess is that you need to select the lines after 19 and indent them (by pressing tab).
Remember: All code inside a function needs to have the same indentation or else the computer will struggle to understand it. Indent is the spaces right before each line.
ใใfor example, this text is indented because it is slightly to the right. -
I'm glad to have been helpful to you!
As for the automatic switching should be relatively simple. You'll need to make a "timer" variable to track how long it has been. Then you check to see if the timer reached a certain number:var timer = 0 #This creates the timer variable. Put it at the very top func _process(delta): timer += delta #delta is how many seconds elapsed since the last time the code was run. It might be a bit confusing at first but this code is just to make the timer actually count like a timer. if timer >= 10: #when the timer reaches 10 seconds, reset the timer to 0, and go to the next section. timer = 0 current += 1 #same code as before visible_ratio = 0
Hope this helps! Read the comments to better understand it
-
Hi, I might have talked about myself a little bit before, but it's about time I make an actual introduction here. I'm lemu_kymoh, and I also go by kymoh for short.
Some random things about me:
I love russian hardbass. I can speak Japanese semi-fluently, but I was born and raised in America. My current favorite game is Escape from Tarkov. I am also into the ๆฑๆน Project game series.Things about me actually related to Godot:
Before Godot, I have been using Unity for several months. I'm still currently making a project there. But I'm trying to learn Godot because my friend wanted to collaborate with me and he uses this game engine.
Anyways I've been taking a very strange strategy to learn Godot. Instead of making my own games, I check this website every few days and try to solve any coding problems. I feel like it's a win-win because they get help with their issues, and I get better at putting my thoughts into GDScript .I hope I can help more people in the future and also learn more about Godot myself! Thanks for having me!
-
I made a code to make the item move towards the closest point on the circle.
Basically, I noticed that if you drew an imaginary line from the center of the circle to the item, the line eventually touches the closest point on the circle.
Since want to find the slope of that line, use arctan(y/x) to find the angle. With the slope, you can then find the x and y coordinates of the point on the circle. This is done by cos(angle)radius and sin(angle)radius.
Now that you have the desired x and y coordinates, simply move the item towards that direction.Note that since Godot measures x and y from the top left corner, you have to go through weird conversions to make it work with trig:
extends Node2D var radius = 250 var phase = 0 var speed = 100 var angular_speed = .2 var clockwise = -1 #-1 for clockwise, 1 for counter-clockwise var x var y var angle var xgoal var ygoal var movement func _ready(): position = Vector2(randf_range(0,get_viewport_rect().size.x),randf_range(0,get_viewport_rect().size.y)) set_xy() angle = atan2(y, x) #find the angle from the center of the circle to the position xgoal = radius*cos(angle) #using that angle, find the coordinates of where that would be on the circle ygoal = radius*sin(angle) movement = Vector2(xgoal - x, -(ygoal - y)).normalized() #direction the item should travel func set_xy(): #sets the x and y coordinates, then offsets the values so that (0, 0) is at the center of the screen (instead of the top left ocrner) x = position.x - get_viewport_rect().size.x/2 y = -(position.y - get_viewport_rect().size.y/2)
Alright, I hope it makes sense and works for you. I also completed the second half of the code.
This part checks if the item is close enough to the edge, then activates the next phase.
In the second phase, the code simply increases the angle slowly, then converts the angle to the coordinates on the circle.
The code should work if you just add it on to the end of the first half:func _process(delta): if phase == 0: phase0(delta) if phase == 1: phase1(delta) func phase0(delta): #moving the item towards the edge of the circle. End this phase once close enough to the edge position += movement * speed * delta set_xy() #(next several lines) measuring how far it is from the edge, then go to next phase if it's close enough var distance = Vector2(xgoal-x, -(ygoal-y)).length() if distance<5: phase = 1 func phase1(delta): #circling around after reaching the edge angle += angular_speed * clockwise * delta #increase the angle slowly xgoal = radius * cos(angle) #(next several lines) finding and converting the angle to coordinates. ygoal = -radius * sin(angle) xgoal += get_viewport_rect().size.x/2 ygoal += get_viewport_rect().size.y/2 position = Vector2(xgoal, ygoal)
-
Sorry for not seeing your question until this late.
Could you please elaborate on where you are having trouble, and what you have working so far?
-Are you having trouble spawning the object in a random place?
-Or are you unable to find the closest point on the circle?
-Perhaps you have the first 2 steps complete, but you just can't make it move along the circumference?And a few minor questions:
-Will the object spawn inside the circle, outside the circle, or both?
-Does the circle always stay in the center, and will it change size later in-game?
-How much math can you understand?I will try coming up with something, but I might struggle as well
-
I think I'm finally beginning to understand your entire project... it seems like you are trying to make something similar to a "slideshow" that allows you to go to the next section when you press a button.
Since you are using text, I recommend an array to hold each section, and use Input to switch to the next element. If you don't know what an array is, it is basically a list that lets you store several variables (strings/text in this case), then access each one whenever you want. Each variable that is stored in an array is called an element.
This way, you can keep the text scrolling down. But, it will only show the sections that you want. I will be attaching the code and images in case you need help.
extends RichTextLabel @export var texts: PackedStringArray #holds all the sections of text. @export lets you edit it in the inspector. var current = 0 #a number variable to keep track of which section you are on. func _ready(): visible_ratio = 1 current = 0 func _process(delta): visible_ratio += delta * 0.07 #scrolling text = texts[current] #set the text to the correct section, depending on the variable "current" if visible_ratio == 1: #resetting scrolling after it reaches the bottom visible_ratio = 0 if Input.is_action_just_pressed("ui_right"): #when the right arrow is pressed: current += 1 #go to the next section visible_ratio=0 #reset the scrolling if current >= texts.size(): #OPTIONAL CODE: checking if it already went to the last section current =0
I added some comments so you can understand what everything means. It's still the same script as before, but with some more added.
Now, the code is not enough. You need to add the text into the array. Just add a new element for each section, and copy/paste the text in there.
https://imgur.com/a/41NRROh -
I meant you need to make a script for RichTextLabel and then you should see a _process function inside it. I will attach a image.
(This is me in the future. I couldn't upload the image so here is a link to it)
https://imgur.com/a/kyVtk57 -
The whole script is attached to the RichTextLabel, and the code that I sent should go inside the process function.
-
Oops, I misunderstood! But I was able to figure it out again
To make it scroll from top to bottom, is pretty similar as my message above but with a RichTextLabel:-
Use the RichTextLabel node, and write the text in it.
-
In the inspector (far right), turn off Scroll Active, and turn on Scroll Following. Basically, scroll following automatically scrolls down to the bottom.
-
Now just add a script. The code is actually the exact same as the one from before!
Remember that this method is easy but there are some shortcomings. One is that the text comes in letter-by-letter, so it might be a little awkward to read. Also, you will need to add a few spaces at the end so that people have enough time to read it all.
Anyway, I hope this helps!
-
-
Do you mean the words come from the right and move to the left?
I found a simple way to do it:-
Use a "Label" node, and write the text in it
-
In the inspector (far right), turn on "Clip Text." This is to make the box cut off.
-
Also in the inspector you should see "Displayed Text." Inside it there's a slider called "Visible Ratio." Notice how moving it will change the amount of letters.
-
Set the Horizontal Alignment to Right. Now when you move the Visible Ratio, the text comes in scrolling.
-
You can still see the end of the text, so just add spaces at the end.
-
The last part is the script to change Visible Ratio automatically. Thankfully you just put simple code like this, in the process function:
visible_ratio += delta * 0.1 if visible_ratio == 1: visible_ratio = 0
-
-
Being able to hand-draw your weapons sounds like an awesome idea! It would be difficult though.
A simple method that comes to my mind is to use a variable such as a Vector2 List, and record where your mouse was drawing. So for each line you would store two Vector2 positions in order to keep track where the line starts and ends. Then, during the game, you would "redraw" the weapon and offset it depending on the player location.
A second method is to use image files that you put into the game. The person playing can draw a weapon, whether that be in an in-game editor or on their own drawing app. Then the drawing would go into the game files so that the game can find it and use it.
Third method is not quite drawing your weapons, but a bit similar. You just pre-draw several different gun parts, then allow the player to switch between them freely. With enough parts, the player can still design whatever they want, and it would make stats really easy to make. I've actually made a small game that uses this method, so I can confirm it's easier than making a drawing editor.
It all depends on what exactly you have planned. The first method is easy for the player but might be hard to make. The second method gives a ton of artistic freedom, but can be confusing for the player to use. The third method is really easy for the player, but takes away the freedom to draw.
-
I'm not sure what your problem is, I tested several buttons and they didn't have issues. If you send a photo or video of your game and code, I might be able to see what went wrong.
Other than that, all I can tell you is to make sure all of your buttons are identical, just to narrow down the inconsistencies. -
I'm not too sure what your error is, so please elaborate if I misunderstood your problem.
It seems like everything would instantly start working if you deleted "sprite." from all of your code. It worked for me.
frame = randi_range(0,sprite_frames.get_frame_count(animation)-1)
Also, remember to change "get_sprite_frames" to "get_frame_count".
Also also, simply typing "animation" gives the current animation that it's using. -
ใใใใจ็ณใใพใใใใใใใ้กใใใพใ
ไปใซๆฅๆฌไบบใใใพใใใ -
Yep, the code lets you change the picture of the item later, during the game.
You would put it in the script for whichever items need to change their picture.So for example, I am guessing your card items will change pictures during the game, so you would set up textures for each card. Then, you can change the current picture:
var new_picture = load("res://new_pic.png")
$Sprite2D.texture = new_picture -
The error you are getting is because the entire "if" statement needs to be in one line.
From your screenshot, you can see that after "or" in line 38, you made it a new line, which gives the error.It is very important to understand that GDscript, similar to Python, relies heavily on white space (indents, spaces, lines). So if you accidentally press enter or tab on the wrong place, the computer won't understand it and give an error.
-
The video was really helpful.
I watched it in slow motion and I realized that for all of your shots (not just horizontal), your grenade would go upwards just a little bit, then quickly corrects itself to go the right way. So it seems like something in the grenade code is making it go up when it gets made.Sure enough, the direction starts at Vector2.UP, and the _process function makes it move in that direction.
But at the same time, in the "Level" scene you properly set the grenade's "linear_velocity" to its direction right after making it. So my thinking is that it takes a little bit of time to set the linear_velocity so the grenade defaults to going up for a split second.I believe the solution would be to make the starting direction (in Grenade scene) to Vector2.ZERO, that way it doesn't try to move when it gets made.
Basic Layouts
Basic Layouts
Basic Layouts
Basic Layouts
Basic Layouts
Hello! A proper introduction (finally)
Help with straight movement into circular movement? (Godot 4.x, Godot 4.2.1)
Help with straight movement into circular movement? (Godot 4.x, Godot 4.2.1)
Basic Layouts
Basic Layouts
Basic Layouts
Basic Layouts
Basic Layouts
New Game Idea
Is it a bug or am I doing something wrong?
How to get the total number of frames in an AnimatedSprite2D animation? (Godot 4.2, 4.x)
ๆฅๆฌใณใใฅใใใฃใฎๆๅใฎใในใ
Basic Layouts
Basic Layouts
Projectile behavior issue