Ask

64 Topics 173 Posts
  • 0 Votes
    2 Posts
    414 Views
    7. Mark the Solution ✔️

    Once you receive an answer that solves your problem, mark it as the solution. This will help others with similar issues find the right answer quickly.

    Remember, It's a Collaborative Space! 🤝

    The Help & Troubleshooting subcategory is all about collaboration and learning from one another. Don't hesitate to share your knowledge, offer insights, and engage in discussions. Together, we can create a supportive environment where everyone can grow their Godot skills.

    Happy asking!

  • 0 Votes
    1 Posts
    2k Views
    No one has replied
  • 0 Votes
    3 Posts
    540 Views

    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)
  • 0 Votes
    1 Posts
    123 Views
    No one has replied
  • 0 Votes
    1 Posts
    121 Views
    No one has replied
  • Help please!!!

    0 Votes
    1 Posts
    78 Views
    No one has replied
  • 0 Votes
    1 Posts
    92 Views
    No one has replied
  • Overlapping item issues?

    0 Votes
    4 Posts
    189 Views

    I am glad it is working now. Hopefully you can get around the delay.

  • 0 Votes
    1 Posts
    92 Views
    No one has replied
  • Multiple idle animations

    1 Votes
    2 Posts
    360 Views

    I believe the other idle animations do not work because the "direction" variable is not being properly set. You want to play an idle animation whenever the velocity of x and y is 0. But then just above it, your code tries to set "direction" depending on the velocities that are greater/lesser than 0. Does my explanation make sense? Velocity cannot be 0 in order to set a direction but at the same time it must be 0 to play the idle animation.

    The solution is to make a variable that keeps track of the direction/velocity only while the object is moving.
    Make a new variable like "last_velocity," then keep setting it to velocity IF velocity is not 0 (in handleInput). Then, you could use last_velocity to set direction (in updateAnimation).

  • 1 Votes
    1 Posts
    120 Views
    No one has replied
  • 0 Votes
    1 Posts
    85 Views
    No one has replied
  • Trouble

    1 Votes
    3 Posts
    106 Views

    Have you tried changing the directory to a different folder? (i.e. a random godot saves folder on your desktop)

  • This topic is deleted!

    0 Votes
    2 Posts
    11 Views
  • 1 Votes
    3 Posts
    176 Views

    It is glb file

  • 1 Votes
    2 Posts
    215 Views

    I'm not sure if this is the issue, but has the acceleration value always been 200 because that might be the problem considering the fact that it's acting as the weight for the linear interpolation. I would try lowering it to like 5. Otherwise I don't see anything that would cause that. I guess that's the point of forums, since you can get multiple perspectives at once.

  • 1 Votes
    2 Posts
    984 Views

    While I have no experience with shaders, in Godot any variant can be converted to bytes by using var_to_bytes and bytes can be converted back again to variant using bytes_to_var

    For example,

    var v3array : PackedVector3Array = [Vector3.ZERO,Vector3.ONE,Vector3.LEFT] print(v3array) # To convert it into bytes var v3array_bytes : PackedByteArray = var_to_bytes(v3array) # To convert it back again from bytes to PackedVector3Array var convert : PackedVector3Array = bytes_to_var(v3array_bytes) print(convert)

    Hope it helps :gok:

  • 1 Votes
    2 Posts
    124 Views

    I'm not too well-versed in the Godot engine thus far, but my best guess would be to check that the texture's filter is set to "Nearest" as opposed to anything that blurs the pixels like "Inherit" or "Linear"

  • Question about mobile control

    1 Votes
    2 Posts
    169 Views

    I'm not sure whether or not you've figured it out by now, but for mobile devices you need to use buttons as your controls, as it's the only feasible way to interact with the Godot engine at the moment (besides tapping the screen). As for tutorials I would look to the Godot documentation on UI elements, or watch a tutorial on buttons.

  • 0 Votes
    3 Posts
    240 Views

    Man, I need to start solving my own problems, because at the expense of around 10 hours of my time and a little bit of sanity, I've finally fixed it! For any of you trying to make a movement FPS in Godot for whatever reason, you can use this as a base. It's klunky, but it works:

    if (velocity.x <= 0 && -velocity.x <= max_speed || velocity.x <= 0 && velocity.x * direction.x < 0): velocity.x += direction.x * air_accel * delta; if (velocity.z <= 0 && -velocity.z <= max_speed || velocity.z <= 0 && velocity.z * direction.z < 0): velocity.z += direction.z * air_accel * delta; if (velocity.x >= 0 && velocity.x <= max_speed || velocity.x >= 0 && velocity.x * direction.x < 0): velocity.x += direction.x * air_accel * delta; if (velocity.z >= 0 && velocity.z <= max_speed || velocity.z >= 0 && velocity.z * direction.z < 0): velocity.z += direction.z * air_accel * delta;