I'm trying to make my button move to a different Vector2i coordinate

Godot Version

4.4.1.stable

Question

I wrote a method that creates a new button and it shows at the starting city as intended. However, I would like that button to move to the destination city on a world map, showing how far it traveled to it’s destination. I don’t know how to do that. Below is the code I have so far ( have the starting and destination coordinates stored in global variables):

func airship_transit():
	if WorldMap.cargo_income != 0:
		var airship_btn = Button.new()
		airship_btn.icon = airship_sprite
		airship_btn.flat = true
		airship_btn.position = map_to_local(WorldMap.cities[WorldMap.current_city]) #<--- starting location
		#WorldMap.destination_city_vector <---- destination
		add_child(airship_btn)
		airship_btn.pressed.connect(self.button_pressed.bind())
		WorldMap.cargo_income = 0

If I’m understanding correctly, you want the button to spawn at one city, then move to the new city over time.

If this is the case, you can either tween it, or you can add a sccript to the button that has a _process() function that updates it over time until it reaches its destination.

1 Like

Understood. If I use the tween method, is it possible to increase the duration temporarily mid-movement? I may want to simulate wind resistance, “slowing down” the speed of the airship.

You could…

What you’d have to do is declare the tween variable as a class-scoped variable. Then if you had wind resistance you’d have to delete the tween, create a new one, then when the wind is gone, do the same thing again.

If you just put the velocity in a _process() function, you could just have a wind resistance variable as part of the equation all the time and just change it for however long you wanted to.

Thank you. Gives me some ideas to tinker with, appreciate it!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.