godot-2d-movement
यह क्या करती है
यह स्किल Godot में CharacterBody2D नोड और उसके move फ़ंक्शन से 2D किरदार कंट्रोलर लिखने में मार्गदर्शन देती है। यह उन Godot डेवलपर्स के लिए है जो प्लेटफ़ॉर्मर या टॉप-डाउन खिलाड़ी और दुश्मनों की गति बना रहे हैं।
कब इस्तेमाल करें
- ✓जब आप Godot में 2D खिलाड़ी या दुश्मन का कंट्रोलर कोड कर रहे हों।
- ✓जब कोई Godot किरदार ज़मीन में धँस जाए या is_on_floor हमेशा false दे।
- ✓जब आप प्लेटफ़ॉर्मर की छलाँग या टॉप-डाउन आठ दिशाओं की गति बना रहे हों।
Skill का लिंक
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/godot/godot-2d-movement/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं Godot 4.7 में एक प्लेटफ़ॉर्मर बना रहा हूँ। क्या आप दौड़ने, गुरुत्वाकर्षण और छलाँग के लिए CharacterBody2D स्क्रिप्ट लिख सकते हैं?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट हर फ़िज़िक्स स्टेप पर वेलोसिटी सेट करता है, गुरुत्वाकर्षण जोड़ता है, और खिलाड़ी को सिर्फ़ तब कूदने देता है जब वह ज़मीन छू रहा हो। फिर वह move फ़ंक्शन कॉल करता है, जो टक्करें संभालता है। टॉप-डाउन गति में गुरुत्वाकर्षण की जगह दिशा वाला सदिश इस्तेमाल होता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Godot 2D Movement (4.x)
Build responsive 2D character controllers with CharacterBody2D and the argument-less
move_and_slide(). Targets Godot 4.7.
When to use
- Use when scripting a 2D player/enemy that moves and collides: platformer (gravity + jump) or top-down (free 8-direction), slope walking, or wall/floor detection.
- Use when
move_and_slide()"does nothing", the character sinks through floors, oris_on_floor()is always false.
When not to use: dynamic rigid bodies, areas, raycasts, collision layers →
godot-physics; tile-based levels → godot-tilemap; full platformer game template →
the platformer genre skill; engine-agnostic feel tuning → physics-tuning.
Core workflow
- Use
CharacterBody2Dwith aCollisionShape2Dchild. It is script-driven: it does not fall or react to forces on its own. - Set the
velocityproperty, then callmove_and_slide()(no arguments in 4.x). The method readsvelocity, moves the body, slides along surfaces, and updatesvelocityto reflect what actually happened. - Do it in
_physics_process(delta)—move_and_slide()uses the physics step's delta internally, so do not multiplyvelocitybydeltayourself. - Platformer: add gravity to
velocity.yeach tick, jump by settingvelocity.ynegative whenis_on_floor(). - Top-down: build a direction from input and scale by speed; set
motion_mode = MOTION_MODE_FLOATINGso there is no "floor/wall" distinction. - Read results with
is_on_floor(),is_on_wall(),get_wall_normal(), andget_slide_collision(i)after the call.
Patterns
1. Platformer controller (gravity, jump, slopes)
extends CharacterBody2D
@export var speed := 200.0
@export var jump_velocity := -400.0
@export var gravity := 1200.0 # pixels/sec^2 (tune to taste)
func _physics_process(delta: float) -> void:
# Apply gravity while airborne.
if not is_on_floor():
velocity.y += gravity * delta
# Jump only when grounded (Input action set in Project Settings > Input Map).
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocity
# Horizontal input: -1, 0, or 1.
var dir := Input.get_axis("move_left", "move_right")
if dir != 0.0:
velocity.x = dir * speed
else:
velocity.x = move_toward(velocity.x, 0.0, speed) # decelerate to a stop
move_and_slide() # 4.x: no arguments; uses and updates `velocity`
A fixed gravity export keeps tuning simple. To follow the project setting
(Physics > 2D > Default Gravity) and any Area2D gravity overrides instead, use
velocity += get_gravity() * delta, as the built-in CharacterBody2D script template does.
2. Top-down 8-direction movement
extends CharacterBody2D
@export var speed := 220.0
func _ready() -> void:
motion_mode = CharacterBody2D.MOTION_MODE_FLOATING # no floor/ceiling concept
func _physics_process(_delta: float) -> void:
# get_vector returns a normalized-ish Vector2 from four input actions.
var input := Input.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = input * speed
move_and_slide()
3. Reading slide collisions after moving
func _physics_process(delta: float) -> void:
# ... set velocity ...
move_and_slide()
for i in get_slide_collision_count():
var c := get_slide_collision(i)
var other := c.get_collider()
if other and other.is_in_group("enemies"):
take_damage(1) # touched an enemy while moving
4. Coyote time (forgiving jump just after leaving a ledge)
@export var coyote_time := 0.1
var _coyote := 0.0
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity.y += gravity * delta
_coyote -= delta
else:
_coyote = coyote_time
if Input.is_action_just_pressed("jump") and _coyote > 0.0:
velocity.y = jump_velocity
_coyote = 0.0
# ... horizontal input + move_and_slide() ...
Pitfalls
- 3.x signature is gone.
move_and_slide(velocity)(returning the new velocity) was removed. In 4.x set thevelocityproperty and callmove_and_slide()with no args.move_and_slide(velocity, Vector2.UP)will not parse. - Multiplying velocity by delta.
move_and_slide()already accounts for the physics delta. Settingvelocity = dir * speed * deltamak
अक्सर पूछे जाने वाले सवाल
क्या मुझे वेलोसिटी को delta से गुणा करना चाहिए?
नहीं। स्किल कहती है कि move फ़ंक्शन अंदर से फ़िज़िक्स स्टेप इस्तेमाल करता है, इसलिए वेलोसिटी को delta से गुणा नहीं करना चाहिए।
क्या यह Godot फ़िज़िक्स बॉडी कवर करती है?
नहीं। रिजिड बॉडी, एरिया और रेकास्ट Godot फ़िज़िक्स स्किल में कवर होते हैं।
क्या यह टाइल वाले लेवल कवर करती है?
टाइल वाले लेवल Godot टाइलमैप स्किल में कवर होते हैं।
जानकारी
लेखक का मूल विवरण
Implement 2D kinematic character movement in Godot 4.7 with CharacterBody2D and move_and_slide(): platformer run/jump with gravity, top-down 8-direction motion, slope handling, and reading collisions. Use when coding a 2D player or enemy controller, a platformer or top-down character, or fixing move_and_slide()/ is_on_floor() behavior in a .tscn with a CharacterBody2D.
लोकप्रियता
- GitHub स्टार
- 6.6k
- रैंकिंग में स्थान
- #13816
- लाइसेंस
- Apache-2.0
- अपडेट की गई
- 28/10/2026
कमेंट
- …
इस repository की और skills
router
6.6kयह आपके एजेंट को इंजन और काम के प्रकार को पहचानकर किसी अनुरोध के लिए सही गेम डेवलपमेंट स्किल चुनने में मदद करती है।
ai-behavior-trees-utility-ai
6.6kयह आपके एजेंट को दुश्मनों और किरदारों के लिए बिहेवियर ट्री और यूटिलिटी AI सिस्टम बनाने में मदद करती है, जो प्राथमिकता और स्कोर से कार्रवाई चुनें।
audio-design
6.6kआपके एजेंट को गेम ऑडियो मिक्सिंग सिखाती है: बस, डेसिबल में वॉल्यूम, डायलॉग में म्यूज़िक धीमा करना और साउंड इफ़ेक्ट की विविधता।
camera-systems
6.6kयह आपके एजेंट को ऐसे गेम कैमरा बनाने में मदद करती है जो सहजता से पीछा करें, लेवल के भीतर रहें, और 3D में घूम या देख सकें।
मिलती-जुलती skills
diffs
394kयह आपके एजेंट को बदलावों का असली diff बनाने देती है, जिसे व्यूअर लिंक या इमेज फ़ाइल के रूप में साझा किया जा सकता है, हाथ से लिखे सारांश के बजाय।
coding-agent
394kयह आपके एजेंट को बड़े कोडिंग काम Codex, Claude Code या OpenCode को बैकग्राउंड वर्कर के रूप में सौंपने, फिर उसकी प्रगति जांचने में मदद करती है।
gh-issues
394kयह आपके एजेंट को GitHub issues खोजने, उनमें से काम करने लायक चुनने, और सुधार के साथ pull requests खोलने में मदद करती है, जिसमें समीक्षा टिप्पणियों का फ़ॉलो-अप भी शामिल है।