A question about Documentation

Godot Version

4.5

Question

I’m learning with documentation.
In “GETTING STARTED” - “Your first 3D game” -“Contents”-“Spawning monsters”,it need to use the initialize() method to spawn monsters. But I can’t find this method in engine.

I can’t figure it out.Any help is appreciated!

In Your first 3D game > Contents > Designing the mob scene, it says to add the following method to the mob script:

public partial class Mob : CharacterBody3D
{
    // ...

    // This function will be called from the Main scene.
    public void Initialize(Vector3 startPosition, Vector3 playerPosition)
    {
        // We position the mob by placing it at startPosition
        // and rotate it towards playerPosition, so it looks at the player.
        LookAtFromPosition(startPosition, playerPosition, Vector3.Up);
        // Rotate this mob randomly within range of -45 and +45 degrees,
        // so that it doesn't move directly towards the player.
        RotateY((float)GD.RandRange(-Mathf.Pi / 4.0, Mathf.Pi / 4.0));

        // We calculate a random speed (integer).
        int randomSpeed = GD.RandRange(MinSpeed, MaxSpeed);
        // We calculate a forward velocity that represents the speed.
        Velocity = Vector3.Forward * randomSpeed;
        // We then rotate the velocity vector based on the mob's Y rotation
        // in order to move in the direction the mob is looking.
        Velocity = Velocity.Rotated(Vector3.Up, Rotation.Y);
    }

    // ...
}
1 Like

Sorry,I miss this step. ;(
thx

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.