Search Results
6/30/2025, 7:15:26 PM
6/18/2025, 5:17:31 PM
>>713001739
That's a cool project — Crusader: No Remorse is a great inspiration. Calculating the shooting direction from the mouse in an isometric 3D setup in Godot 4 is definitely doable, but since you're working in an orthogonal isometric camera in 3D, it requires translating 2D mouse input into a 3D world-space direction relative to your player character.
Here’s a structured way to handle this in Godot 4:
>Step 1: Get Mouse Position in World
You'll need to project the 2D mouse cursor into a ray in world space, then find where that ray intersects with the game's floor plane (Y = 0).
func get_mouse_world_position() -> Vector3:
var viewport := get_viewport()
var mouse_pos := viewport.get_mouse_position()
var ray_origin := $Camera3D.project_ray_origin(mouse_pos)
var ray_direction := $Camera3D.project_ray_normal(mouse_pos)
# Define a plane at Y = 0 (ground level)
var plane := Plane(Vector3.UP, 0)
var intersection := plane.intersects_ray(ray_origin, ray_direction)
if intersection != null:
return intersection
else:
return Vector3.ZERO
This function gives you the world position on the ground plane where the mouse is pointing.
>Step 2: Calculate Shooting Direction
Now that you have the point on the ground, subtract the player's position to get a direction vector:
func get_shoot_direction() -> Vector3:
var mouse_world_pos := get_mouse_world_position()
var player_pos := global_transform.origin
var direction := (mouse_world_pos - player_pos).normalized()
return direction
This direction vector can now be used to:
Spawn projectiles.
Rotate the player or gun toward that direction.
Trigger effects (like muzzle flashes or aiming indicators).
That's a cool project — Crusader: No Remorse is a great inspiration. Calculating the shooting direction from the mouse in an isometric 3D setup in Godot 4 is definitely doable, but since you're working in an orthogonal isometric camera in 3D, it requires translating 2D mouse input into a 3D world-space direction relative to your player character.
Here’s a structured way to handle this in Godot 4:
>Step 1: Get Mouse Position in World
You'll need to project the 2D mouse cursor into a ray in world space, then find where that ray intersects with the game's floor plane (Y = 0).
func get_mouse_world_position() -> Vector3:
var viewport := get_viewport()
var mouse_pos := viewport.get_mouse_position()
var ray_origin := $Camera3D.project_ray_origin(mouse_pos)
var ray_direction := $Camera3D.project_ray_normal(mouse_pos)
# Define a plane at Y = 0 (ground level)
var plane := Plane(Vector3.UP, 0)
var intersection := plane.intersects_ray(ray_origin, ray_direction)
if intersection != null:
return intersection
else:
return Vector3.ZERO
This function gives you the world position on the ground plane where the mouse is pointing.
>Step 2: Calculate Shooting Direction
Now that you have the point on the ground, subtract the player's position to get a direction vector:
func get_shoot_direction() -> Vector3:
var mouse_world_pos := get_mouse_world_position()
var player_pos := global_transform.origin
var direction := (mouse_world_pos - player_pos).normalized()
return direction
This direction vector can now be used to:
Spawn projectiles.
Rotate the player or gun toward that direction.
Trigger effects (like muzzle flashes or aiming indicators).
Page 1