본문으로 건너뛰기
cccskills
무료GitHub에 공개

bevy-character-movement

Bevy 0.20 kinematic character movement: intent components, FixedUpdate integration, coyote time, and jump buffer. Use when a player or actor walks or jumps and the step must stay stable. Keywords: Bevy, movement, FixedUpdate, coyote, jump buffer, ECS.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md9.9 KB
  • references/ecs-ownership.md537 B

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Bevy character movement

When to use

Load this when a Bevy app needs a player or actor that moves in discrete steps (walk, jump feel, ground check) and you need the ECS shape before any solver code exists. Coyote time and a jump buffer are design notes. They are not a node port.

ECS shape

  • Components own pose and intent: position, velocity, and a jump-buffer or coyote timer as data. The Quick Start ECS page shows components as Rust structs that derive Component.
  • Resources own clocks and tuning shared by every mover. bevy::time 0.20.0 documents Time, Fixed (fixed timestep clock), and Virtual.
  • Systems read intent and write velocity or position. Register them on the fixed schedule, not on a per-node physics callback.
  • Schedule: run_fixed_main_schedule runs FixedMain from virtual time (bevy::time 0.20.0). Order dependent systems with .chain() (ECS page). Do not paste a Godot physics-process function.

Engine counterparts

Godot ideaBevy idiom
Body that you move yourselfEntity with movement components and a system
Step that should stay stable when frame time changesSystem on the fixed timestep (Fixed / FixedMain)
Coyote time, jump bufferTimer data on the entity or a small resource, consumed by the movement system
Collision responseCollision response belongs on bevy-physics-3d.

Scope

Locomotion here is kinematic data on FixedUpdate: intent, velocity, coyote time, and a jump buffer. Collision response belongs on bevy-physics-3d. Do not call move_and_slide, _physics_process, or CharacterBody2D.

[dependencies]
bevy = "0.20"
#[derive(Component, Default)]
struct PlanarIntent {
    axis: Vec2,
    jump_pressed: bool,
}

#[derive(Component)]
struct KinematicBody {
    velocity: Vec3,
    grounded: bool,
    coyote: f32,
    jump_buffer: f32,
}

#[derive(Resource)]
struct MoveTuning {
    speed: f32,
    jump_speed: f32,
    gravity: f32,
    coyote_time: f32,
    jump_buffer_time: f32,
}

impl Default for MoveTuning {
    fn default() -> Self {
        Self {
            speed: 6.0,
            jump_speed: 8.0,
            gravity: 20.0,
            coyote_time: 0.12,
            jump_buffer_time: 0.12,
        }
    }
}

fn read_move_intent(keys: Res<ButtonInput<KeyCode>>, mut bodies: Query<&mut PlanarIntent>) {
    let mut axis = Vec2::ZERO;
    if keys.pressed(KeyCode::KeyA) {
        axis.x -= 1.0;
    }
    if keys.pressed(KeyCode::KeyD) {
        axis.x += 1.0;
    }
    let jump_pressed = keys.just_pressed(KeyCode::Space);
    for mut intent in &mut bodies {
        intent.axis = axis;
        intent.jump_pressed = jump_pressed;
    }
}

fn step_kinematic(
    time: Res<Time<Fixed>>,
    tuning: Res<MoveTuning>,
    mut bodies: Query<(&mut PlanarIntent, &mut KinematicBody, &mut Transform)>,
) {
    let dt = time.delta_secs();
    for (mut intent, mut body, mut transform) in &mut bodies {
        body.velocity.x = intent.axis.x * tuning.speed;
        if body.grounded {
            body.coyote = tuning.coyote_time;
        } else {
            body.coyote = (body.coyote - dt).max(0.0);
            body.velocity.y -= tuning.gravity * dt;
        }
        if intent.jump_pressed {
            body.jump_buffer = tuning.jump_buffer_time;
            intent.jump_pressed = false;
        } else {
            body.jump_buffer = (body.jump_buffer - dt).max(0.0);
        }
        if body.jump_buffer > 0.0 && body.coyote > 0.0 {
            body.velocity.y = tuning.jump_speed;
            body.jump_buffer = 0.0;
            body.coyote = 0.0;
            body.grounded = false;
        }
        transform.translation += body.velocity * dt;
        if transform.translation.y <= 0.0 {
            transform.translation.y = 0.0;
            body.velocity.y = 0.0;
            body.grounded = true;
        }
    }
}

fn spawn_mover(mut commands: Commands) {
    commands.spawn((
        Transform::default(),
        PlanarIntent::default(),
        KinematicBody {
            velocity: Vec3::ZERO,
            grounded: true,
            coyote: 0.0,
            jump_buffer: 0.0,
        },
    ));
}

pub struct CharacterMovementPlugin;

impl Plugin for CharacterMovementPlugin {
    fn build(&self, app: &mut App) {
        app.init_resource::<MoveTuning>()
            .add_systems(Startup, spawn_mover)
            .add_systems(Update, read_move_intent)
            .add_systems(FixedUpdate, step_kinematic);
    }
}

Sample ButtonInput::just_pressed in Update. FixedUpdate can run zero times or several times in one frame, so a press read there is dropped or repeated. The intent component keeps the edge until FixedUpdate consumes it.

When a physics skill writes Grounded, chain the coyote refill after that write so the timer sees the contact from the same tick.

#[derive(Component)]
struct Grounded;

#[derive(Component)]
struct CoyoteTimer(f32);

#[derive(Resource)]
struct CoyoteWindow(f32);

fn refill_coyote(window: Res<CoyoteWindow>, mut movers: Query<&mut CoyoteTimer, With<Grounded>>) {
    for mut timer in &mut movers {
        timer.0 = window.0;
    }
}

fn tick_coyote(time: Res<Time<Fixed>>, mut movers: Query<&mut CoyoteTimer, Without<Grounded>>) {
    let dt = time.delta_secs();
    for mut timer in &mut movers {
        timer.0 = (timer.0 - dt).max(0.0);
    }
}

pub struct CoyotePlugin;

impl Plugin for CoyotePlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource(CoyoteWindow(0.12)).add_systems(
            FixedUpdate,
            (refill_coyote, tick_coyote).chain(),
        );
    }
}

Expert Knowledge Delta

Target: Bevy 0.20+.

Core ECS types: Component, Resource, Query, Commands, Startup, Update, Fixed / FixedMain (bevy::time), .chain(), Plugin, DefaultPlugins, MinimalPlugins. Messages and observers are an ownership slot. See bevy-events-messaging for their APIs. Systems run in parallel unless .chain() orders the ones that conflict.

Who owns state

PieceOwnerWho may mutateSchedule
Data on one entityComponentOne system via QueryUpdate or FixedMain
One value for the whole appResourceOne systemStartup to insert, then the schedule that reads it
SpawnCommandsThe spawning systemStartup for the initial world; later schedules for runtime spawn
Order that must not race.chain()The chained systems onlySame schedule
Plugin boundaryPluginbuild registers systems and resourcesBefore the app runs

Borrow rule: two systems that both mutably query the same component must be ordered (.chain()) or split so only one writes. Unrelated systems stay parallel. That is the ECS page rule, not a guess at a system-set API.

Decision

If you needDo thisDo not
Per-entity dataComponent + QueryA Godot node script
App-wide config or clockResourceCopy the value onto every entity
Stable simulation stepFixedMain and the Fixed clockTie simulation to raw frame Update
Startup spawnCommands in StartupSpawn from a render system
Cross-system notice that is not shared stateMessage or observer slot in bevy-events-messagingA new event type invented in this file
An API outside this skillLoad the skill that owns itA made-up crate or API

Load references/ecs-ownership.md for the ownership table.

NEVER

  • Do not pin /0.20.0/ in docs URLs. WHY: links stay on latest; the 0.20 target is stated once in prose.
  • Do not step locomotion on raw Update when the step must stay stable. WHY: bevy::time documents Fixed and run_fixed_main_schedule (FixedMain) for a fixed clock.
  • Do not read ButtonInput::just_pressed inside FixedUpdate. WHY: that schedule can skip a frame or run more than once, so the press is lost or applied twice.
  • Do not call move_and_slide, _physics_process, or CharacterBody2D. WHY: those are Godot types. This skill only owns ECS movement data.
  • Do not invent a character-controller or shape-cast API. WHY: this skill owns kinematic intent and the fixed step; contact queries live on the physics skills.
  • Do not mutably query the same movement component from two unordered systems. WHY: systems run in parallel unless .chain() orders them.

Reference

The library pin on bevy-master stays 0.20.0. Official pages stay on the unversioned site.

Official Documentation

  • Quick Start: ECS - Entities, Component, systems, Query, Commands, and .chain().
  • Fixed timestep - Fixed and FixedMain via run_fixed_main_schedule on the ECS schedule page.
  • Examples - Example tree on the latest branch.

Related Skills

Prerequisites

  • bevy-master - ECS ownership, schedules, and which Bevy skill to load.

Complements

Downstream / consumers

  • Genre skills cover loop and encounter design.

Master

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Bevy ECS skill for 2D sprite animation. Keywords: Bevy, sprite, animation, AnimationPlayer, AnimationClip, 2D.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

thedivergentai/Game-Dev-Agentic-Skills8792026년 10월 17일 업데이트

Spawn and tune Bevy 0.20 directional, point, and spot lights, cascade shadows, distance fog, and a nearest-light shadow budget. Use when a 3D scene needs a sun, local lights, or fog on the camera. Keywords: DirectionalLight, PointLight, SpotLight, CascadeShadowConfig, DistanceFog, bevy_light.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

thedivergentai/Game-Dev-Agentic-Skills8792026년 10월 17일 업데이트

Bevy ECS skill for PBR materials. Keywords: Bevy, StandardMaterial, PBR, material, ExtendedMaterial.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

thedivergentai/Game-Dev-Agentic-Skills8792026년 10월 17일 업데이트

Bevy ECS skill for 3D level assembly. Keywords: Bevy, level, scene, mesh, world, ECS.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

thedivergentai/Game-Dev-Agentic-Skills8792026년 10월 17일 업데이트

Bevy ECS skill for abilities. Keywords: Bevy, ability, cooldown, ECS, gameplay.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

thedivergentai/Game-Dev-Agentic-Skills8792026년 10월 17일 업데이트

Rewrite Bevy 2D actors and cameras into 3D meshes and Camera3d while keeping gameplay components. Use when a Bevy 2D game should gain a perspective camera, mesh draw, and a planar velocity lifted onto XZ. Keywords: Camera2d, Camera3d, Sprite, Mesh3d, StandardMaterial, WishVelocity.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

thedivergentai/Game-Dev-Agentic-Skills8792026년 10월 17일 업데이트

thedivergentai의 스킬 모두 보기

이 스킬의 문제 신고