Create with C# a dynamic capsul with dynamic animation?

Godot Version

Godot.Net Version 4.2.1


I’m new with Godot and love .NET. I love it to write my own class librarys.

Can anyone show me please a script (in C#?) to create a capsul and add and play a animation like “crounch” for the Capsul?

I try this since many hours, and google can’t help me. Sorry.

Thank you!!! :slight_smile:

you never said if this is a 2d or 3d game.

if you create a CharacterBody2D and add a c# script to it, Godot will offer create a simple c# example to get you started.

most examples are in gdscript, but if you are good with c#, it isn’t that difficult to rewrite gdscript for c#.

using Godot;
using System;

public partial class CharacterBody2D : Godot.CharacterBody2D
	public const float Speed = 300.0f;
	public const float JumpVelocity = -400.0f;

	// Get the gravity from the project settings to be synced with RigidBody nodes.
	public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();

	public override void _PhysicsProcess(double delta)
		Vector2 velocity = Velocity;

		// Add the gravity.
		if (!IsOnFloor())
			velocity.Y += gravity * (float)delta;

		// Handle Jump.
		if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
			velocity.Y = JumpVelocity;

		// Get the input direction and handle the movement/deceleration.
		// As good practice, you should replace UI actions with custom gameplay actions.
		Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
		if (direction != Vector2.Zero)
			velocity.X = direction.X * Speed;
			velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);

		Velocity = velocity;

Thank you, but, this is a simply 2D moving object, not animating object.

I need a script for a 3d Object, like capsule, created dynamic in C#. And the capsule-object need a animation (like crounch).

just a note for whoever, there is also a related discussion here → Create Animation in C# for Capsule-Characterbody3D - #3 by AndyB09

Yes, and i ask again: Can i make a script (with C#) that create a 3D object, like a capsule, and create dynamik a animation, like crounch?