Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
lamarmarshall / res.txt
Created March 2, 2025 15:02
godot mobile resolution
540
960
@lamarmarshall
lamarmarshall / raycast.gd
Created March 2, 2025 12:59
godot, raycast
extends Camera3D
@onready var ray_cast_3d: RayCast3D = $RayCast3D
@export var grid_map: GridMap
@export var turret_manager: Node3D
@export var turret_cost := 100
@onready var bank := get_tree().get_first_node_in_group("Bank")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
@lamarmarshall
lamarmarshall / ts.cs
Created March 2, 2025 03:21
unity, touch screen
using UnityEngine;
using UnityEngine.InputSystem;
public class BallHandler : MonoBehaviour
{
private Camera mainCamera;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
mainCamera = Camera.main;
@lamarmarshall
lamarmarshall / turret.gd
Created March 1, 2025 19:44
godot 4, aim, shoot
extends Node3D
@export var projectile: PackedScene
@onready var turret_top: MeshInstance3D = $TurretBase/TurretTop
var enemy_path: Path3D
func _physics_process(delta: float) -> void:
var enemy = enemy_path.get_children().back()
look_at(enemy.global_position, Vector3.UP, true)
@lamarmarshall
lamarmarshall / bullet.gd
Created March 1, 2025 19:26
godot, projectile, bullet move
extends Area3D
var direction := Vector3.FORWARD
@export var speed := 30.0
func _physics_process(delta: float) -> void:
position += direction * speed * delta
@lamarmarshall
lamarmarshall / gun.gd
Created March 1, 2025 19:17
godot 4, spawn bullet
extends Node3D
@export var projectile: PackedScene
func _ready() -> void:
var shot = projectile.instantiate()
add_child(shot)
@lamarmarshall
lamarmarshall / turret.gd
Created March 1, 2025 17:18
godot, spawn
extends Node3D
@export var turret: PackedScene
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var new_turret = turret.instantiate()
add_child(new_turret)
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()
@lamarmarshall
lamarmarshall / color.gd
Created March 1, 2025 14:35
godot, change color over time
var red: Color = Color.RED
var white: Color = Color.WHITE
var blended_color = red.lerp(white, float(current_health) / float(max_health))
label_3d.modulate = blended_color
@lamarmarshall
lamarmarshall / getter.gd
Created March 1, 2025 14:29
godot, gdscript, getter, setter
var current_health: int:
set(health_in):
current_health = health_in
print("health was changed")
label_3d.text = str(current_health) + "/" + str(max_health)
var red: Color = Color.RED
var white: Color = Color.WHITE
var blended_color = red.lerp(white, float(current_health) / float(max_health))
label_3d.modulate = blended_color
if current_health < 1: