Created
March 1, 2025 17:15
-
-
Save lamarmarshall/48e5a04f13974e3a44ad4e5850c2f89a to your computer and use it in GitHub Desktop.
godot, raycast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Camera3D | |
@onready var ray_cast_3d: RayCast3D = $RayCast3D | |
@export var grid_map: GridMap | |
# Called every frame. 'delta' is the elapsed time since the previous frame. | |
func _process(delta: float) -> void: | |
var mouse_position: Vector2 = get_viewport().get_mouse_position() | |
ray_cast_3d.target_position = project_local_ray_normal(mouse_position) * 100.0 | |
ray_cast_3d.force_raycast_update() | |
if ray_cast_3d.is_colliding(): | |
var collider = ray_cast_3d.get_collider() | |
if collider is GridMap: | |
var collision_point = ray_cast_3d.get_collision_point() | |
var cell = grid_map.local_to_map(collision_point) | |
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND) | |
#make sure gride cel isst to item 0 | |
if Input.is_action_just_pressed("click"): | |
if grid_map.get_cell_item(cell) == 0: | |
grid_map.set_cell_item(cell, 1) | |
else: | |
Input.set_default_cursor_shape(Input.CURSOR_ARROW) | |
#printt(ray_cast_3d.get_collider(), ray_cast_3d.get_collision_point()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment