I am having trouble getting a simple enemy to move in my Godot 4 project using C#.
The sprite doesn’t move when I run the scene.
My scene structure is
Slime (CharacterBody2D)
├── AnimatedSprite2D
└── Killzone
└── CollisionShape2D
using Godot;
using System;
public partial class Slime : CharacterBody2D
{
[Export]
public float speedSlime = 60f;
public override void _PhysicsProcess(double delta)
{
// Setting velocity and using MoveAndSlide
Velocity = new Vector2(speedSlime, 0);
MoveAndSlide();
}
}
Based on just the code alone, this should work as you’d expect.
The few things I can think of are:
Make sure the CollisionShape2D actually has a collision shape resource added to it
Make sure you compiled and saved the scene after you added the script to it, it’s not automatically saved if you just run the project from your IDE, you need to save it in godot first.
The collisionShape2D has rectangle shape and its a child node of killzone.
└── Killzone
└── CollisionShape2D
I don’t know what compile is.
I guess its the build project thing? If so I did it before run the game.
Idk man, thank you for reply tho.