Godot:RigidBody2D
godot - RigidBody2D. 2D 물리 엔진에 의해 제어되는 강체.
물리엔진 적용된 캐릭터
하위 노드로, 다음을 추가.
- Sprite - 캐릭터 이미지 적용.
- CollisionShape2D - 캐릭터 충돌 감지.
APIs
-
MoveLocalY(x)
: Y축 이동.
Signals
-
body_entered
: 객체 충돌 이벤트.
속도 변경 예제
using Godot;
using System;
public class Piano : Node2D
{
public RigidBody2D player;
private Godot.Vector2 speed = new Godot.Vector2(0, -100);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
player = GetNode("Player") as RigidBody2D;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(float delta)
{
if (Godot.Input.IsActionJustPressed("ui_accept"))
{
GD.Print("Left Mouse.");
player.SetLinearVelocity(speed);
}
}
}