Godot Version
4.5.1
Question
Goal: Cheap good looking scenes for prototypes mechanics
Need to reach: 3d character walking on the 2d photo but flawlessly
first i added root 3d world node, then Sprite3d, rotate it by y-axis, give root node static body and collision shape3d, make ant farm from collision shapes, add camera and player (no gravity in player script), asked gpt to cheap way through this, he said “Add Path3d => Make the curve => In player scipt look for position and if not match tolarance don’t add velocity” i tried that but in my interpretation it didn’t work, can somebody help me?
(player has decrease for up down for imitation of distance and approach)
(If it can’t be done so easily, then it would have been easier to build the desired shape from rectangles from the very beginning; it would have taken less time than searching for a solution in a “quick” way
)
If you share code, please wrap it inside three backticks or replace the code in the next block:
extends CharacterBody3D
const SPEED = 5.0 # Твоя базовая скорость
@export var path: Path3D
@export var road_half_width := 1.5
@onready var anim_player = $"Clean New Male Ultimate/AnimationPlayer"
@export var min_size: float = 0.3
@export var max_size: float = 1.2
func _ready() -> void:
print("!!! СТАРТ: Теперь я РЕАЛЬНЫЙ CharacterBody3D, скрипт ожил !!!")
func _physics_process(delta):
# Обнуляем скорость по X и Z перед каждым кадром,
# чтобы персонаж останавливался, если кнопку отпустили
velocity.x = 0
velocity.z = 0
velocity.y = 0
# Set absolute scale (doubles the original size)
# Вычисляем текущую скорость прямо здесь.
# Если scale.x = 0.5, то скорость будет 5 * 0.5 = 2.5
# Если scale.x = 1.0, то скорость будет 5 * 1 = 5
#там чел сказал закоментить и норм будет склей если
# scale = Vector3(1.0, 1.0, 1.0)
# Прямые проверки через just_pressed (или просто pressed, если хочешь удержанием)
# Если хочешь, чтобы бежал пока держишь — меняй на is_action_pressed
if Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
if Input.is_action_pressed("ui_up"):
velocity.y += 0.5
scale = scale - Vector3(0.1, 0.1, 0.1)
if scale.y < min_size:
scale = Vector3(min_size, min_size, min_size)
if Input.is_action_pressed("ui_down"):
velocity.y -= 1.5
scale = scale + Vector3(0.1, 0.1, 0.1)
if scale.y > max_size:
scale = Vector3(max_size, max_size, max_size)
# ===== Ограничение дорожкой =====
var next_pos = global_position + Vector3(velocity.x, 0.0, velocity.z) * delta
var curve = path.curve
var offset = curve.get_closest_offset(next_pos)
var center = curve.sample_baked(offset)
if next_pos.distance_to(center) > road_half_width:
print('я пытаюсь ограничить но не получается')
velocity.x = 0
velocity.z = 0
# ===============================
# Применяем движение
move_and_slide()