![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Smoodie |
Hi im new in godot (4.0), i switched from unity to godot today, im making a basic movement system and im already stuck bcz of an error (is probably a dumb thing)
here is my code :
using Godot;
public class PlayerController : CharacterBody2D
{
public const float Speed = 150.0f;
public override void _PhysicsProcess(float delta)
{
Vector2 velocity = Vector2.Zero;
Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down").Normalized();
if (direction != Vector2.Zero)
{
velocity = direction * Speed;
GetNode<AnimatedSprite2D>("AnimatedSprite2D").Play("run");
GetNode<AnimatedSprite2D>("AnimatedSprite2D").FlipH = direction.x < 0;
}
else
{
GetNode<AnimatedSprite2D>("AnimatedSprite2D").Play("default");
}
Velocity = velocity;
MoveAndSlide(Velocity);
}
}
edit : i repeated the whole projects and i have 2 errors now lol
1 - PlayerController.cs(3,1): Missing partial modifier on declaration of type ‘PlayerController’ which is a subclass of ‘Godot.GodotObject’
2 - PlayerController.cs(7,26): ‘PlayerController._PhysicsProcess(float)’: no suitable method found to override
(is actually the same script i didnt change it)
Are you sure this is the code that’s generating the error you reported? I ask as it doesn’t contain a reference to anything named Player
.
jgodfrey | 2023-03-03 21:42
is actually the only script i have, CharacterBody2D is named Player in the scene tho
edit : i repeated the whole projects and i have 2 errors now lol
1 - PlayerController.cs(3,1): Missing partial modifier on declaration of type ‘PlayerController’ which is a subclass of ‘Godot.GodotObject’
2 - PlayerController.cs(7,26): ‘PlayerController._PhysicsProcess(float)’: no suitable method found to override
(is actually the same script i didnt change it)
Smoodie | 2023-03-03 22:13
You need to add the keyword partial
as the error indicates:
public partial class PlayerController
This is because godot also implements a PlayerController for its own use and declaring methods your code can then override. When godot generates a new script, it adds the partial keyword automatically.
spaceyjase | 2023-03-04 08:44