#How can i make my character go around certain tiles
1 messages · Page 1 of 1 (latest)
You can use the same logic as normal movement and just rotate the final result by 45º
would i want to use CharacterBody2D or is there a better node for this?
It really depends on what you're doing.
If you're using the bult in physics, CharacterBody is perfect.
im just after something that can move to where i click on my tilemap, but i cant find any good sources on how to set it up
Am still struggling to workout the movement not sure how to have the character be on the first layer of the tile map
Just want to be able to have characters I can select and move to points on the tile map to explore, gather, etc
How can i make my character go around certain tiles
extends CharacterBody2D
var speed = 300
var click_position = Vector2()
var target_position = Vector2()
func _ready():
click_position = position
func _physics_process(delta):
if Input.is_action_just_pressed("Right_Click"):
click_position = get_global_mouse_position()
if position.distance_to(click_position) > 3:
target_position = (click_position - position).normalized()
velocity = target_position * speed
move_and_slide()
i have been able to get a working movement system but am unsure how make it move around certain objects like ones i have marked as buildings
You would need to implement some sort of pathfinding algorithm for that, first, you need to define a traversable space, you could do it using the TileMapLayers u have there, second you need to make an algorithm that uses that defined space to try an reach the goal position, like moving in the direction of the goal, until it reaches it or encounters an obstacle, if the later happens, you would need to move in another direction, and try again.
Thankfully, godot already does that for you, check this documentation: https://docs.godotengine.org/en/stable/tutorials/navigation/navigation_introduction_2d.html
Godot provides multiple objects, classes and servers to facilitate grid-based or mesh-based navigation and pathfinding for 2D and 3D games. The following section provides a quick overview over all ...
Since it seems this is your first time with pathfinding, i would recommend doing more research and looking up some tutorials, since this is quite a complex topic to simply explain it here.