Godot:RigidBody2D
lastmod 2020-11-08created 2020-09-207 edits
godot - RigidBody2D. A rigid body controlled by the 2D physics engine.
Character with the physics engine applied
Add the following as child nodes.
- Sprite - Applies the character image.
- CollisionShape2D - Detects character collisions.
APIs
-
MoveLocalY(x): Moves along the Y axis.
Signals
-
body_entered: Object collision event.
Velocity change example
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);
}
}
}