mirror of
https://github.com/godotengine/godot-docs.git
synced 2025-12-31 17:49:03 +03:00
Merge pull request #6313 from mhilbrunner/fix-refs-and-renames
Fix refs and renames
This commit is contained in:
@@ -333,3 +333,4 @@ source,destination
|
||||
/tutorials/viewports/multiple_resolutions.html,/tutorials/rendering/multiple_resolutions.html
|
||||
/tutorials/viewports/using_viewport_as_texture.html,/tutorials/shaders/using_viewport_as_texture.html
|
||||
/tutorials/viewports/viewports.html,/tutorials/rendering/viewports.html
|
||||
/tutorials/physics/using_kinematic_body_2d.html,/tutorials/physics/using_character_body_2d.html
|
||||
|
||||
|
@@ -270,14 +270,14 @@ From the Oxford dictionary:
|
||||
|
||||
::
|
||||
|
||||
Create a KinematicBody2D node, a CollisionShape2D node and a sprite node.
|
||||
Create a CharacterBody2D node, a CollisionShape2D node and a sprite node.
|
||||
|
||||
**Do** add a comma before `and` or `or`, for the last
|
||||
element of a list with more than two elements.
|
||||
|
||||
::
|
||||
|
||||
Create a KinematicBody2D node, a CollisionShape2D node, and a sprite node.
|
||||
Create a CharacterBody2D node, a CollisionShape2D node, and a sprite node.
|
||||
|
||||
|
||||
How to write methods and classes
|
||||
@@ -483,7 +483,7 @@ The Animation, Debugger, etc. at the bottom of the viewport are
|
||||
|
||||
Foldable areas of the Inspector are ``sections``. The node's parent
|
||||
class names, which you can't fold, are ``Classes`` e.g. the
|
||||
``KinematicBody2D class``. And individual lines with key-value pairs are
|
||||
``CharacterBody2D class``. And individual lines with key-value pairs are
|
||||
``properties``. E.g. ``position`` or ``modulate color`` are both
|
||||
``properties``.
|
||||
|
||||
|
||||
@@ -247,14 +247,14 @@ More information can be found on the :ref:`doc_godot_notifications` page.
|
||||
References
|
||||
----------
|
||||
|
||||
:ref:`Reference <class_ReferenceCounted>` inherits from Object and holds a
|
||||
:ref:`RefCounted <class_RefCounted>` inherits from Object and holds a
|
||||
reference count. It is the base for reference counted object types.
|
||||
Declaring them must be done using Ref<> template. For example:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
class MyReference: public Reference {
|
||||
GDCLASS(MyReference, Reference);
|
||||
class MyReference: public RefCounted {
|
||||
GDCLASS(MyReference, RefCounted);
|
||||
};
|
||||
|
||||
Ref<MyReference> myref(memnew(MyReference));
|
||||
@@ -265,7 +265,7 @@ templates point to it.
|
||||
References:
|
||||
~~~~~~~~~~~
|
||||
|
||||
- `core/object/reference.h <https://github.com/godotengine/godot/blob/master/core/object/reference.h>`__
|
||||
- `core/object/reference.h <https://github.com/godotengine/godot/blob/master/core/object/ref_counted.h>`__
|
||||
|
||||
Resources:
|
||||
----------
|
||||
|
||||
@@ -11,11 +11,11 @@ that moves in eight directions.
|
||||
.. player_movement.gif
|
||||
|
||||
Create a new scene by going to the Scene menu in the top-left and clicking *New
|
||||
Scene*. Create a *KinematicBody* node as the root and name it *Player*.
|
||||
Scene*. Create a *CharacterBody3D* node as the root and name it *Player*.
|
||||
|
||||
|image0|
|
||||
|
||||
Kinematic bodies are complementary to the area and rigid bodies used in the 2D
|
||||
Character bodies are complementary to the area and rigid bodies used in the 2D
|
||||
game tutorial. Like rigid bodies, they can move and collide with the
|
||||
environment, but instead of being controlled by the physics engine, you dictate
|
||||
their movement. You will see how we use the node's unique features when we code
|
||||
|
||||
@@ -19,7 +19,7 @@ character.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# How fast the player moves in meters per second.
|
||||
@export var speed = 14
|
||||
@@ -30,7 +30,7 @@ character.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Player : KinematicBody
|
||||
public class Player : CharacterBody3D
|
||||
{
|
||||
// Don't forget to rebuild the project so the editor knows about the new export variable.
|
||||
|
||||
@@ -214,8 +214,8 @@ The physics engine can only detect interactions with walls, the floor, or other
|
||||
bodies during a given frame if movement and collisions happen. We will use this
|
||||
property later to code the jump.
|
||||
|
||||
On the last line, we call ``KinematicBody.move_and_slide()``. It's a powerful
|
||||
method of the ``KinematicBody`` class that allows you to move a character
|
||||
On the last line, we call ``CharacterBody3D.move_and_slide()``. It's a powerful
|
||||
method of the ``CharacterBody3D`` class that allows you to move a character
|
||||
smoothly. If it hits a wall midway through a motion, the engine will try to
|
||||
smooth it out for you.
|
||||
|
||||
@@ -233,7 +233,7 @@ Here is the complete ``Player.gd`` code for reference.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# How fast the player moves in meters per second.
|
||||
@export var speed = 14
|
||||
@@ -266,7 +266,7 @@ Here is the complete ``Player.gd`` code for reference.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Player : KinematicBody
|
||||
public class Player : CharacterBody3D
|
||||
{
|
||||
// How fast the player moves in meters per second.
|
||||
[Export]
|
||||
|
||||
@@ -9,7 +9,7 @@ next lesson, we'll spawn them randomly around the playable area.
|
||||
Let's design the monsters themselves in a new scene. The node structure is going
|
||||
to be similar to the *Player* scene.
|
||||
|
||||
Create a scene with, once again, a *KinematicBody* node as its root. Name it
|
||||
Create a scene with, once again, a *CharacterBody3D* node as its root. Name it
|
||||
*Mob*. Add a *Spatial* node as a child of it, name it *Pivot*. And drag and drop
|
||||
the file ``mob.glb`` from the *FileSystem* dock onto the *Pivot* to add the
|
||||
monster's 3D model to the scene. You can rename the newly created *mob* node
|
||||
@@ -100,7 +100,7 @@ the ``velocity``.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# Minimum speed of the mob in meters per second.
|
||||
@export var min_speed = 10
|
||||
@@ -115,7 +115,7 @@ the ``velocity``.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Mob : KinematicBody
|
||||
public class Mob : CharacterBody3D
|
||||
{
|
||||
// Don't forget to rebuild the project so the editor knows about the new export variable.
|
||||
|
||||
@@ -135,7 +135,7 @@ the ``velocity``.
|
||||
}
|
||||
|
||||
Similarly to the player, we move the mob every frame by calling
|
||||
``KinematicBody``\ 's ``move_and_slide()`` method. This time, we don't update
|
||||
``CharacterBody3D``\ 's ``move_and_slide()`` method. This time, we don't update
|
||||
the ``velocity`` every frame: we want the monster to move at a constant speed
|
||||
and leave the screen, even if it were to hit an obstacle.
|
||||
|
||||
@@ -254,7 +254,7 @@ Here is the complete ``Mob.gd`` script for reference.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# Minimum speed of the mob in meters per second.
|
||||
@export var min_speed = 10
|
||||
@@ -281,7 +281,7 @@ Here is the complete ``Mob.gd`` script for reference.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Mob : KinematicBody
|
||||
public class Mob : CharacterBody3D
|
||||
{
|
||||
// Minimum speed of the mob in meters per second
|
||||
[Export]
|
||||
|
||||
@@ -157,7 +157,7 @@ called ``move_and_slide()``.
|
||||
|
||||
That's all you need to jump!
|
||||
|
||||
The ``is_on_floor()`` method is a tool from the ``KinematicBody`` class. It
|
||||
The ``is_on_floor()`` method is a tool from the ``CharacterBody3D`` class. It
|
||||
returns ``true`` if the body collided with the floor in this frame. That's why
|
||||
we apply gravity to the *Player*: so we collide with the floor instead of
|
||||
floating over it like the monsters.
|
||||
@@ -258,7 +258,7 @@ With this code, if no collisions occurred on a given frame, the loop won't run.
|
||||
for (int index = 0; index < GetSlideCount(); index++)
|
||||
{
|
||||
// We check every collision that occurred this frame.
|
||||
KinematicCollision collision = GetSlideCollision(index);
|
||||
KinematicCollision3D collision = GetSlideCollision(index);
|
||||
// If we collide with a monster...
|
||||
if (collision.Collider is Mob mob && mob.IsInGroup("mob"))
|
||||
{
|
||||
@@ -276,11 +276,11 @@ With this code, if no collisions occurred on a given frame, the loop won't run.
|
||||
That's a lot of new functions. Here's some more information about them.
|
||||
|
||||
The functions ``get_slide_count()`` and ``get_slide_collision()`` both come from
|
||||
the :ref:`KinematicBody<class_KinematicBody>` class and are related to
|
||||
the :ref:`CharacterBody3D<class_CharacterBody3D>` class and are related to
|
||||
``move_and_slide()``.
|
||||
|
||||
``get_slide_collision()`` returns a
|
||||
:ref:`KinematicCollision<class_KinematicCollision>` object that holds
|
||||
:ref:`KinematicCollision3D<class_KinematicCollision3D>` object that holds
|
||||
information about where and how the collision occurred. For example, we use its
|
||||
``collider`` property to check if we collided with a "mob" by calling
|
||||
``is_in_group()`` on it: ``collision.collider.is_in_group("mob")``.
|
||||
|
||||
@@ -52,7 +52,7 @@ one to the *Player* node. In the *Node* tab, double-click the
|
||||
|
||||
|image4|
|
||||
|
||||
The *MobDetector* will emit ``body_entered`` when a *KinematicBody* or a
|
||||
The *MobDetector* will emit ``body_entered`` when a *CharacterBody3D* or a
|
||||
*RigidBody* node enters it. As it only masks the "enemies" physics
|
||||
layers, it will only detect the *Mob* nodes.
|
||||
|
||||
@@ -228,7 +228,7 @@ Next is ``Mob.gd``.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# Emitted when the player jumped on the mob.
|
||||
signal squashed
|
||||
@@ -264,7 +264,7 @@ Next is ``Mob.gd``.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Mob : KinematicBody
|
||||
public class Mob : CharacterBody3D
|
||||
{
|
||||
// Emitted when the played jumped on the mob.
|
||||
[Signal]
|
||||
@@ -311,7 +311,7 @@ Finally, the longest script, ``Player.gd``.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# Emitted when a mob hit the player.
|
||||
signal hit
|
||||
@@ -373,7 +373,7 @@ Finally, the longest script, ``Player.gd``.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Player : KinematicBody
|
||||
public class Player : CharacterBody3D
|
||||
{
|
||||
// Emitted when the player was hit by a mob.
|
||||
[Signal]
|
||||
@@ -435,7 +435,7 @@ Finally, the longest script, ``Player.gd``.
|
||||
|
||||
for (int index = 0; index < GetSlideCount(); index++)
|
||||
{
|
||||
KinematicCollision collision = GetSlideCollision(index);
|
||||
KinematicCollision3D collision = GetSlideCollision(index);
|
||||
if (collision.Collider is Mob mob && mob.IsInGroup("mob"))
|
||||
{
|
||||
if (Vector3.Up.Dot(collision.Normal) > 0.1f)
|
||||
|
||||
@@ -282,7 +282,7 @@ Here's the *Player* script.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# Emitted when the player was hit by a mob.
|
||||
signal hit
|
||||
@@ -349,7 +349,7 @@ Here's the *Player* script.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Player : KinematicBody
|
||||
public class Player : CharacterBody3D
|
||||
{
|
||||
// Emitted when the player was hit by a mob.
|
||||
[Signal]
|
||||
@@ -416,7 +416,7 @@ Here's the *Player* script.
|
||||
|
||||
for (int index = 0; index < GetSlideCount(); index++)
|
||||
{
|
||||
KinematicCollision collision = GetSlideCollision(index);
|
||||
KinematicCollision3D collision = GetSlideCollision(index);
|
||||
if (collision.Collider is Mob mob && mob.IsInGroup("mob"))
|
||||
{
|
||||
if (Vector3.Up.Dot(collision.Normal) > 0.1f)
|
||||
@@ -449,7 +449,7 @@ And the *Mob*'s script.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
# Emitted when the player jumped on the mob.
|
||||
signal squashed
|
||||
@@ -487,7 +487,7 @@ And the *Mob*'s script.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Mob : KinematicBody
|
||||
public class Mob : CharacterBody3D
|
||||
{
|
||||
// Emitted when the played jumped on the mob.
|
||||
[Signal]
|
||||
|
||||
@@ -40,7 +40,7 @@ nodes.
|
||||
|
||||
.. image:: img/key_concepts_character_nodes.png
|
||||
|
||||
It is made of a ``KinematicBody2D`` node named "Character", a ``Sprite2D``, a
|
||||
It is made of a ``CharacterBody2D`` node named "Character", a ``Sprite2D``, a
|
||||
``Camera2D``, and a ``CollisionShape2D``.
|
||||
|
||||
.. note:: The node names end with "2D" because this is a 2D scene. Their 3D
|
||||
|
||||
@@ -121,7 +121,7 @@ node, including classes it extends, like ``Node2D``, ``CanvasItem``, and
|
||||
``Node``.
|
||||
|
||||
.. note:: In GDScript, if you omit the line with the ``extends`` keyword, your
|
||||
class will implicitly extend :ref:`Reference <class_Reference>`, which
|
||||
class will implicitly extend :ref:`RefCounted <class_RefCounted>`, which
|
||||
Godot uses to manage your application's memory.
|
||||
|
||||
Inherited properties include the ones you can see in the Inspector dock, like
|
||||
|
||||
@@ -10,7 +10,7 @@ Every beginner has been there: "How do I move my character?" Depending on the
|
||||
style of game you're making, you may have special requirements, but in general
|
||||
the movement in most 2D games is based on a small number of designs.
|
||||
|
||||
We'll use :ref:`KinematicBody2D <class_KinematicBody2D>` for these examples,
|
||||
We'll use :ref:`CharacterBody2D <class_CharacterBody2D>` for these examples,
|
||||
but the principles will apply to other node types (Area2D, RigidBody2D) as well.
|
||||
|
||||
.. _doc_2d_movement_setup:
|
||||
@@ -18,7 +18,7 @@ but the principles will apply to other node types (Area2D, RigidBody2D) as well.
|
||||
Setup
|
||||
-----
|
||||
|
||||
Each example below uses the same scene setup. Start with a ``KinematicBody2D`` with two
|
||||
Each example below uses the same scene setup. Start with a ``CharacterBody2D`` with two
|
||||
children: ``Sprite2D`` and ``CollisionShape2D``. You can use the Godot icon ("icon.png")
|
||||
for the Sprite2D's texture or use any other 2D image you have.
|
||||
|
||||
@@ -41,7 +41,7 @@ Add a script to the kinematic body and add the following code:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
export (int) var speed = 200
|
||||
|
||||
@@ -68,7 +68,7 @@ Add a script to the kinematic body and add the following code:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Movement : KinematicBody2D
|
||||
public class Movement : CharacterBody2D
|
||||
{
|
||||
[Export] public int speed = 200;
|
||||
|
||||
@@ -129,7 +129,7 @@ while up/down moves it forward or backward in whatever direction it's facing.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
export (int) var speed = 200
|
||||
export (float) var rotation_speed = 1.5
|
||||
@@ -159,7 +159,7 @@ while up/down moves it forward or backward in whatever direction it's facing.
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Movement : KinematicBody2D
|
||||
public class Movement : CharacterBody2D
|
||||
{
|
||||
[Export] public int speed = 200;
|
||||
[Export] public float rotationSpeed = 1.5f;
|
||||
@@ -216,7 +216,7 @@ is set by the mouse position instead of the keyboard. The character will always
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
export (int) var speed = 200
|
||||
|
||||
@@ -239,7 +239,7 @@ is set by the mouse position instead of the keyboard. The character will always
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Movement : KinematicBody2D
|
||||
public class Movement : CharacterBody2D
|
||||
{
|
||||
[Export] public int speed = 200;
|
||||
|
||||
@@ -291,7 +291,7 @@ on the screen will cause the player to move to the target location.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
export (int) var speed = 200
|
||||
|
||||
@@ -313,7 +313,7 @@ on the screen will cause the player to move to the target location.
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Movement : KinematicBody2D
|
||||
public class Movement : CharacterBody2D
|
||||
{
|
||||
[Export] public int speed = 200;
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ released.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
onready var _animated_sprite = $AnimatedSprite2D
|
||||
|
||||
@@ -88,7 +88,7 @@ released.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Character : KinematicBody2D
|
||||
public class Character : CharacterBody2D
|
||||
{
|
||||
private AnimatedSprite2D _animatedSprite;
|
||||
|
||||
@@ -215,7 +215,7 @@ released.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
onready var _animation_player = $AnimationPlayer
|
||||
|
||||
@@ -227,7 +227,7 @@ released.
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
public class Character : KinematicBody2D
|
||||
public class Character : CharacterBody2D
|
||||
{
|
||||
private AnimationPlayer _animationPlayer;
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ resizing or stretching the screen. This transform is used internally (as
|
||||
described in :ref:`doc_multiple_resolutions`), but can also be manually set
|
||||
on each viewport.
|
||||
|
||||
Input events received in the :ref:`MainLoop._input_event() <class_MainLoop_method__input_event>`
|
||||
callback are multiplied by this transform but lack the ones above. To
|
||||
Input events are multiplied by this transform but lack the ones above. To
|
||||
convert InputEvent coordinates to local CanvasItem coordinates, the
|
||||
:ref:`CanvasItem.make_input_local() <class_CanvasItem_method_make_input_local>`
|
||||
function was added for convenience.
|
||||
|
||||
@@ -58,7 +58,7 @@ The ``_draw()`` function is only called once, and then the draw commands
|
||||
are cached and remembered, so further calls are unnecessary.
|
||||
|
||||
If re-drawing is required because a state or something else changed,
|
||||
call :ref:`CanvasItem.update() <class_CanvasItem_method_update>`
|
||||
call :ref:`CanvasItem.queue_redraw() <class_CanvasItem_method_queue_redraw>`
|
||||
in that same node and a new ``_draw()`` call will happen.
|
||||
|
||||
Here is a little more complex example, a texture variable that will be
|
||||
|
||||
@@ -19,34 +19,34 @@ parameters and then adding randomness to them.
|
||||
Particle nodes
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Godot provides two different nodes for 2D particles, :ref:`class_Particles2D` and
|
||||
Godot provides two different nodes for 2D particles, :ref:`class_GPUParticles2D` and
|
||||
:ref:`class_CPUParticles2D`.
|
||||
Particles2D is more advanced and uses the GPU to process particle effects, but that limits
|
||||
GPUParticles2D is more advanced and uses the GPU to process particle effects, but that limits
|
||||
it to higher end graphics API, and in our case to the GLES3 renderer. For projects using
|
||||
the GLES2 backend, CPUParticles2D is a CPU-driven option with near feature parity with
|
||||
Particles2D, but lesser performance. While Particles2D is configured via a
|
||||
:ref:`class_ParticlesMaterial` (and optionally with a custom shader), the matching options
|
||||
GPUParticles2D, but lesser performance. While GPUParticles2D is configured via a
|
||||
:ref:`class_ParticleProcessMaterial` (and optionally with a custom shader), the matching options
|
||||
are provided via node properties in CPUParticles2D (with the exception of the trail settings).
|
||||
You can convert a Particles2D node into a CPUParticles2D node by clicking on the node in the
|
||||
You can convert a GPUParticles2D node into a CPUParticles2D node by clicking on the node in the
|
||||
inspector, and selecting "Convert to CPUParticles2D" in the "Particles" menu of the toolbar.
|
||||
|
||||
.. image:: img/particles_convert.png
|
||||
|
||||
The rest of this tutorial is going to use the Particles2D node. First, add a Particles2D
|
||||
The rest of this tutorial is going to use the GPUParticles2D node. First, add a GPUParticles2D
|
||||
node to your scene. After creating that node you will notice that only a white dot was created,
|
||||
and that there is a warning icon next to your Particles2D node in the scene dock. This
|
||||
is because the node needs a ParticlesMaterial to function.
|
||||
and that there is a warning icon next to your GPUParticles2D node in the scene dock. This
|
||||
is because the node needs a ParticleProcessMaterial to function.
|
||||
|
||||
ParticlesMaterial
|
||||
~~~~~~~~~~~~~~~~~
|
||||
ParticleProcessMaterial
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
To add a process material to your particles node, go to ``Process Material`` in
|
||||
your inspector panel. Click on the box next to ``Material``, and from the dropdown
|
||||
menu select ``New ParticlesMaterial``.
|
||||
menu select ``New ParticleProcessMaterial``.
|
||||
|
||||
.. image:: img/particles_material.png
|
||||
|
||||
Your Particles2D node should now be emitting
|
||||
Your GPUParticles2D node should now be emitting
|
||||
white points downward.
|
||||
|
||||
.. image:: img/particles1.png
|
||||
@@ -80,7 +80,7 @@ Lifetime: 4.0
|
||||
One Shot
|
||||
~~~~~~~~
|
||||
|
||||
When enabled, a Particles2D node will emit all of its particles once
|
||||
When enabled, a GPUParticles2D node will emit all of its particles once
|
||||
and then never again.
|
||||
|
||||
Preprocess
|
||||
@@ -149,7 +149,7 @@ The rectangle's ``W`` and ``H`` properties respectively control its Width and it
|
||||
The ``X`` and ``Y`` properties control the position of the upper-left
|
||||
corner of the rectangle, relative to the particle emitter.
|
||||
|
||||
You can have Godot generate a Visibility Rect automatically using the toolbar above the 2d view. To do so, select the Particles2D node and Click ``Particles > Generate Visibility Rect``. Godot will simulate the Particles2D node emitting particles for a few seconds and set the rectangle to fit the surface the particles take.
|
||||
You can have Godot generate a Visibility Rect automatically using the toolbar above the 2d view. To do so, select the GPUParticles2D node and Click ``Particles > Generate Visibility Rect``. Godot will simulate the Particles2D node emitting particles for a few seconds and set the rectangle to fit the surface the particles take.
|
||||
|
||||
You can control the emit duration with the ``Generation Time (sec)`` option. The maximum value is 25 seconds. If you need more time for your particles to move around, you can temporarily change the ``preprocess`` duration on the Particles2D node.
|
||||
|
||||
@@ -174,8 +174,8 @@ This controls the order in which individual particles are drawn. ``Index``
|
||||
means particles are drawn according to their emission order (default).
|
||||
``Lifetime`` means they are drawn in order of remaining lifetime.
|
||||
|
||||
ParticlesMaterial settings
|
||||
--------------------------
|
||||
ParticleProcessMaterial settings
|
||||
--------------------------------
|
||||
|
||||
Direction
|
||||
~~~~~~~~~
|
||||
@@ -303,11 +303,11 @@ randomness ratio.
|
||||
Emission Shapes
|
||||
---------------
|
||||
|
||||
ParticlesMaterials allow you to set an Emission Mask, which dictates
|
||||
ParticleProcessMaterials allow you to set an Emission Mask, which dictates
|
||||
the area and direction in which particles are emitted.
|
||||
These can be generated from textures in your project.
|
||||
|
||||
Ensure that a ParticlesMaterial is set, and the Particles2D node is selected.
|
||||
Ensure that a ParticleProcessMaterial is set, and the GPUParticles2D node is selected.
|
||||
A "Particles" menu should appear in the Toolbar:
|
||||
|
||||
.. image:: img/emission_shapes1.png
|
||||
@@ -348,7 +348,7 @@ Emission Colors
|
||||
|
||||
``Capture from Pixel`` will cause the particles to inherit the color of the mask at their spawn points.
|
||||
|
||||
Once you click "OK", the mask will be generated and set to the ParticlesMaterial, under the ``Emission Shape`` section:
|
||||
Once you click "OK", the mask will be generated and set to the ParticleProcessMaterial, under the ``Emission Shape`` section:
|
||||
|
||||
.. image:: img/emission_shapes4.png
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ Interior environments can be created by using inverted primitives.
|
||||
|
||||
.. note:: The CSG nodes in Godot are mainly intended for prototyping. There is
|
||||
no built-in support for UV mapping or editing 3D polygons (though
|
||||
extruded 2D polygons can be used with the CSGPolygon node).
|
||||
extruded 2D polygons can be used with the CSGPolygon3D node).
|
||||
|
||||
If you're looking for an easy to use level design tool for a project,
|
||||
you may want to use `Qodot <https://github.com/Shfty/qodot-plugin>`__
|
||||
@@ -29,13 +29,13 @@ Introduction to CSG nodes
|
||||
Like other features of Godot, CSG is supported in the form of nodes. These are
|
||||
the CSG nodes:
|
||||
|
||||
- :ref:`CSGBox <class_CSGBox>`
|
||||
- :ref:`CSGCylinder <class_CSGCylinder>` (also supports cone)
|
||||
- :ref:`CSGSphere <class_CSGSphere>`
|
||||
- :ref:`CSGTorus <class_CSGTorus>`
|
||||
- :ref:`CSGPolygon <class_CSGPolygon>`
|
||||
- :ref:`CSGMesh <class_CSGMesh>`
|
||||
- :ref:`CSGCombiner <class_CSGcombiner>`
|
||||
- :ref:`CSGBox3D <class_CSGBox3D>`
|
||||
- :ref:`CSGCylinder3D <class_CSGCylinder3D>` (also supports cone)
|
||||
- :ref:`CSGSphere3D <class_CSGSphere3D>`
|
||||
- :ref:`CSGTorus3D <class_CSGTorus3D>`
|
||||
- :ref:`CSGPolygon3D <class_CSGPolygon3D>`
|
||||
- :ref:`CSGMesh3D <class_CSGMesh3D>`
|
||||
- :ref:`CSGCombiner3D <class_CSGCombiner3D>`
|
||||
|
||||
.. image:: img/csg_nodes.png
|
||||
|
||||
@@ -59,7 +59,7 @@ Every CSG node supports 3 kinds of boolean operations:
|
||||
CSGPolygon
|
||||
~~~~~~~~~~
|
||||
|
||||
The :ref:`CSGPolygon <class_CSGPolygon>` node extrude along a Polygon drawn in
|
||||
The :ref:`CSGPolygon3D <class_CSGPolygon3D>` node extrude along a Polygon drawn in
|
||||
2D (in X, Y coordinates) in the following ways:
|
||||
|
||||
- **Depth:** Extruded back a given amount.
|
||||
@@ -71,15 +71,15 @@ The :ref:`CSGPolygon <class_CSGPolygon>` node extrude along a Polygon drawn in
|
||||
|
||||
.. image:: img/csg_poly.png
|
||||
|
||||
.. note:: The **Path** mode must be provided with a :ref:`Path <class_Path>`
|
||||
.. note:: The **Path** mode must be provided with a :ref:`Path3D <class_Path3D>`
|
||||
node to work. In the Path node, draw the path and the polygon in
|
||||
CSGPolygon will extrude along the given path.
|
||||
CSGPolygon3D will extrude along the given path.
|
||||
|
||||
|
||||
Custom meshes
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Any mesh can be used for :ref:`CSGMesh <class_CSGMesh>`; the mesh can be
|
||||
Any mesh can be used for :ref:`CSGMesh3D <class_CSGMesh3D>`; the mesh can be
|
||||
modelled in other software and imported into Godot. Multiple materials are
|
||||
supported. There are some restrictions for geometry:
|
||||
|
||||
@@ -90,10 +90,10 @@ supported. There are some restrictions for geometry:
|
||||
|
||||
.. image:: img/csg_custom_mesh.png
|
||||
|
||||
CSGCombiner
|
||||
~~~~~~~~~~~
|
||||
CSGCombiner3D
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
The :ref:`CSGCombiner <class_CSGCombiner>` node is an empty shape used for
|
||||
The :ref:`CSGCombiner3D <class_CSGCombiner3D>` node is an empty shape used for
|
||||
organization. It will only combine children nodes.
|
||||
|
||||
Processing order
|
||||
@@ -135,44 +135,44 @@ Create a scene with a Spatial node as root node.
|
||||
|
||||
.. image:: img/csg_overdraw.png
|
||||
|
||||
Create a CSGBox and name it ``room``, enable **Invert Faces** and change the
|
||||
Create a CSGBox3D and name it ``room``, enable **Invert Faces** and change the
|
||||
dimensions of your room.
|
||||
|
||||
.. image:: img/csg_room.png
|
||||
|
||||
.. image:: img/csg_room_invert.png
|
||||
|
||||
Next, create a CSGCombiner and name it ``desk``.
|
||||
Next, create a CSGCombiner3D and name it ``desk``.
|
||||
|
||||
A desk has one surface and 4 legs:
|
||||
|
||||
- Create 1 CSGBox children node in **Union** mode for the surface
|
||||
- Create 1 CSGBox3D children node in **Union** mode for the surface
|
||||
and adjust the dimensions.
|
||||
- Create 4 CSGBox children nodes in **Union** mode for the legs
|
||||
- Create 4 CSGBox3D children nodes in **Union** mode for the legs
|
||||
and adjust the dimensions.
|
||||
|
||||
Adjust their placement to resemble a desk.
|
||||
|
||||
.. image:: img/csg_desk.png
|
||||
|
||||
.. note:: CSG nodes inside a CSGCombiner will only process their operation
|
||||
within the combiner. Therefore, CSGCombiners are used to organize
|
||||
.. note:: CSG nodes inside a CSGCombiner3D will only process their operation
|
||||
within the combiner. Therefore, CSGCombiner3Ds are used to organize
|
||||
CSG nodes.
|
||||
|
||||
Create a CSGCombiner and name it ``bed``.
|
||||
Create a CSGCombiner3D and name it ``bed``.
|
||||
|
||||
Our bed consists of 3 parts: the bed, the mattress and a pillow. Create a CSGBox
|
||||
and adjust its dimension for the bed. Create another CSGBox and adjust its
|
||||
Our bed consists of 3 parts: the bed, the mattress and a pillow. Create a CSGBox3D
|
||||
and adjust its dimension for the bed. Create another CSGBox3D and adjust its
|
||||
dimension for the mattress.
|
||||
|
||||
.. image:: img/csg_bed_mat.png
|
||||
|
||||
We will create another CSGCombiner named ``pillow`` as the child of ``bed``.
|
||||
We will create another CSGCombiner3D named ``pillow`` as the child of ``bed``.
|
||||
The scene tree should look like this:
|
||||
|
||||
.. image:: img/csg_bed_tree.png
|
||||
|
||||
We will combine 3 CSGSphere nodes in **Union** mode to form a pillow. Scale the
|
||||
We will combine 3 CSGSphere3D nodes in **Union** mode to form a pillow. Scale the
|
||||
Y axis of the spheres and enable **Smooth Faces**.
|
||||
|
||||
.. image:: img/csg_pillow_smooth.png
|
||||
@@ -186,8 +186,8 @@ Try to re-parent the ``pillow`` node to the root ``Spatial`` node; the hole will
|
||||
disappear.
|
||||
|
||||
.. note:: This is to illustrate the effect of CSG processing order.
|
||||
Since the root node is not a CSG node, the CSGCombiner nodes are
|
||||
the end of the operations; this shows the use of CSGCombiner to
|
||||
Since the root node is not a CSG node, the CSGCombiner3D nodes are
|
||||
the end of the operations; this shows the use of CSGCombiner3D to
|
||||
organize the CSG scene.
|
||||
|
||||
Undo the re-parent after observing the effect. The bed you've built should look
|
||||
@@ -195,16 +195,16 @@ like this:
|
||||
|
||||
.. image:: img/csg_bed.png
|
||||
|
||||
Create a CSGCombiner and name it ``lamp``.
|
||||
Create a CSGCombiner3D and name it ``lamp``.
|
||||
|
||||
A lamp consists of 3 parts: the stand, the pole and the lampshade.
|
||||
Create a CSGCylinder, enable the **Cone** option and make it the stand. Create
|
||||
another CSGCylinder and adjust the dimensions to use it as a pole.
|
||||
Create a CSGCylinder3D, enable the **Cone** option and make it the stand. Create
|
||||
another CSGCylinder3D and adjust the dimensions to use it as a pole.
|
||||
|
||||
.. image:: img/csg_lamp_pole_stand.png
|
||||
|
||||
We will use a CSGPolygon for the lampshade. Use the **Spin** mode for the
|
||||
CSGPolygon and draw a `trapezoid <https://en.wikipedia.org/wiki/Trapezoid>`_
|
||||
We will use a CSGPolygon3D for the lampshade. Use the **Spin** mode for the
|
||||
CSGPolygon3D and draw a `trapezoid <https://en.wikipedia.org/wiki/Trapezoid>`_
|
||||
while in **Front View** (numeric keypad 1); this shape will extrude around the
|
||||
origin and form the lampshade.
|
||||
|
||||
@@ -218,21 +218,21 @@ Adjust the placement of the 3 parts to make it look like a lamp.
|
||||
|
||||
.. image:: img/csg_lamp.png
|
||||
|
||||
Create a CSGCombiner and name it ``bookshelf``.
|
||||
Create a CSGCombiner3D and name it ``bookshelf``.
|
||||
|
||||
We will use 3 CSGBox nodes for the bookshelf. Create a CSGBox and adjust its
|
||||
We will use 3 CSGBox3D nodes for the bookshelf. Create a CSGBox3D and adjust its
|
||||
dimensions; this will be the size of the bookshelf.
|
||||
|
||||
.. image:: img/csg_shelf_big.png
|
||||
|
||||
Duplicate the CSGBox and shorten the dimensions of each axis and change the mode
|
||||
Duplicate the CSGBox3D and shorten the dimensions of each axis and change the mode
|
||||
to **Subtraction**.
|
||||
|
||||
.. image:: img/csg_shelf_subtract.png
|
||||
|
||||
.. image:: img/csg_shelf_subtract_menu.png
|
||||
|
||||
You've almost built a shelf. Create one more CSGBox for dividing the shelf into
|
||||
You've almost built a shelf. Create one more CSGBox3D for dividing the shelf into
|
||||
two levels.
|
||||
|
||||
.. image:: img/csg_shelf.png
|
||||
@@ -261,7 +261,7 @@ to quickly apply textures to CSG-based levels.
|
||||
|
||||
There are two ways to apply a material to a CSG node:
|
||||
|
||||
- Applying it to a CSGCombiner node as a material override
|
||||
- Applying it to a CSGCombiner3D node as a material override
|
||||
(**Geometry > Material Override** in the Inspector). This will affect its
|
||||
children automatically, but will make it impossible to change the material in
|
||||
individual children.
|
||||
|
||||
@@ -56,7 +56,7 @@ Creating the polygons
|
||||
---------------------
|
||||
|
||||
Create a new scene for your model (if it's going to be an animated character,
|
||||
you may want to use a ``KinematicBody2D``). For ease of use, an empty 2D node is
|
||||
you may want to use a ``CharacterBody2D``). For ease of use, an empty 2D node is
|
||||
created as a root for the polygons.
|
||||
|
||||
Begin with a ``Polygon2D`` node. There is no need to place it anywhere in the
|
||||
|
||||
@@ -33,7 +33,7 @@ This is how it's done in the `Third Person Shooter demo <https://github.com/godo
|
||||
|
||||
.. image:: img/animtree1.png
|
||||
|
||||
A new scene was created for the player with a ``KinematicBody`` as root. Inside this scene, the original ``.dae`` (Collada) file was instantiated
|
||||
A new scene was created for the player with a ``CharacterBody3D`` as root. Inside this scene, the original ``.dae`` (Collada) file was instantiated
|
||||
and an ``AnimationTree`` node was created.
|
||||
|
||||
Creating a tree
|
||||
@@ -211,7 +211,7 @@ Afterwards, the actual motion can be retrieved via the :ref:`AnimationTree <clas
|
||||
|
||||
animTree.GetRootMotionTransform();
|
||||
|
||||
This can be fed to functions such as :ref:`KinematicBody.move_and_slide <class_KinematicBody_method_move_and_slide>` to control the character movement.
|
||||
This can be fed to functions such as :ref:`CharacterBody3D.move_and_slide <class_CharacterBody3D_method_move_and_slide>` to control the character movement.
|
||||
|
||||
There is also a tool node, ``RootMotionView``, that can be placed in a scene and will act as a custom floor for your
|
||||
character and animations (this node is disabled by default during the game).
|
||||
|
||||
@@ -29,7 +29,7 @@ is to get a reference to an existing object from another acquired instance.
|
||||
Object obj = node.Object; // Property access.
|
||||
Object obj = node.GetObject(); // Method access.
|
||||
|
||||
The same principle applies for :ref:`Reference <class_Reference>` objects.
|
||||
The same principle applies for :ref:`RefCounted <class_RefCounted>` objects.
|
||||
While users often access :ref:`Node <class_Node>` and
|
||||
:ref:`Resource <class_Resource>` this way, alternative measures are available.
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ consider:
|
||||
would be to unload the entire script. If they are instead loaded
|
||||
properties, then one can set them to ``null`` and remove all references
|
||||
to the resource entirely (which, as a
|
||||
:ref:`Reference <class_Reference>`-extending type, will cause the
|
||||
:ref:`RefCounted <class_RefCounted>`-extending type, will cause the
|
||||
resources to delete themselves from memory).
|
||||
|
||||
Large levels: static vs. dynamic
|
||||
|
||||
@@ -41,8 +41,8 @@ available from the ``ClassDB``.
|
||||
.. note::
|
||||
|
||||
Even scripts that don't use the ``extends`` keyword implicitly inherit from the engine's base
|
||||
:ref:`Reference <class_Reference>` class. As a result, you can instantiate scripts without the
|
||||
``extends`` keyword from code. Since they extend ``Reference`` though, you cannot attach them to
|
||||
:ref:`RefCounted <class_RefCounted>` class. As a result, you can instantiate scripts without the
|
||||
``extends`` keyword from code. Since they extend ``RefCounted`` though, you cannot attach them to
|
||||
a :ref:`Node <class_Node>`.
|
||||
|
||||
Scenes
|
||||
|
||||
@@ -193,7 +193,7 @@ Curve2D, Curve3D, Path and Path2D
|
||||
|
||||
There are two objects that contain curves: :ref:`Curve3D <class_Curve3D>` and :ref:`Curve2D <class_Curve2D>` (for 3D and 2D respectively).
|
||||
|
||||
They can contain several points, allowing for longer paths. It is also possible to set them to nodes: :ref:`Path <class_Path>` and :ref:`Path2D <class_Path2D>` (also for 3D and 2D respectively):
|
||||
They can contain several points, allowing for longer paths. It is also possible to set them to nodes: :ref:`Path3D <class_Path3D>` and :ref:`Path2D <class_Path2D>` (also for 3D and 2D respectively):
|
||||
|
||||
.. image:: img/bezier_path_2d.png
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ Using the following pseudocode:
|
||||
|
||||
Position3D p1 = GetNode<Position3D>("Position1");
|
||||
Position3D p2 = GetNode<Position3D>("Position2");
|
||||
CSGMesh monkey = GetNode<CSGMesh>("Monkey");
|
||||
CSGMesh3D monkey = GetNode<CSGMesh3D>("Monkey");
|
||||
|
||||
monkey.Transform = p1.Transform.InterpolateWith(p2.Transform, _t);
|
||||
}
|
||||
|
||||
@@ -222,8 +222,8 @@ The surface normal has a value of ``(0, -1)`` because this is a horizontal
|
||||
surface. When the ball collides, we take its remaining motion (the amount left
|
||||
over when it hits the surface) and reflect it using the normal. In Godot, the
|
||||
:ref:`Vector2 <class_Vector2>` class has a ``bounce()`` method to handle this.
|
||||
Here is a GDScript example of the diagram above using a :ref:`KinematicBody2D
|
||||
<class_KinematicBody2D>`:
|
||||
Here is a GDScript example of the diagram above using a :ref:`CharacterBody2D
|
||||
<class_CharacterBody2D>`:
|
||||
|
||||
|
||||
.. tabs::
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
Using NavigationAgents
|
||||
======================
|
||||
|
||||
NavigationsAgents are helper nodes to facilitate common calls to the NavigationServer API
|
||||
NavigationsAgents are helper nodes to facilitate common calls to the NavigationServer API
|
||||
on behalf of the parent actor node in a more convenient manner for beginners.
|
||||
|
||||
2D and 3D version of NavigationAgents are available as
|
||||
:ref:`NavigationAgent2D<class_NavigationAgent2D>` and
|
||||
2D and 3D version of NavigationAgents are available as
|
||||
:ref:`NavigationAgent2D<class_NavigationAgent2D>` and
|
||||
:ref:`NavigationAgent3D<class_NavigationAgent3D>` respectively.
|
||||
|
||||
NavigationsAgents are entirely optional for navigation pathfinding.
|
||||
The functionality of NavigationsAgents can be recreated with scripts and direct
|
||||
calls to the NavigationServer API. If the default NavigationsAgent does not do what you want
|
||||
NavigationsAgents are entirely optional for navigation pathfinding.
|
||||
The functionality of NavigationsAgents can be recreated with scripts and direct
|
||||
calls to the NavigationServer API. If the default NavigationsAgent does not do what you want
|
||||
for your game feel free to design your own NavigationsAgent with scripts.
|
||||
|
||||
.. warning::
|
||||
|
||||
NavigationsAgent nodes and NavigationServer ``agents`` are not the same.
|
||||
The later is an RVO avoidance agent and solely used for avoidance.
|
||||
NavigationsAgent nodes and NavigationServer ``agents`` are not the same.
|
||||
The later is an RVO avoidance agent and solely used for avoidance.
|
||||
RVO avoidance agents are not involved in regular pathfinding.
|
||||
|
||||
NavigationAgent Pathfinding
|
||||
@@ -27,23 +27,23 @@ NavigationAgent Pathfinding
|
||||
To use NavigationAgents for pathfinding, place a NavigationAgent2D/3D Node below a Node2D/3D inheriting parent node.
|
||||
|
||||
To have the agent query a path to a target position use the ``set_target_location()`` method.
|
||||
Once the target has been set, the next position to follow in the path
|
||||
can be retrieved with the ``get_next_location()`` function. Move the parent actor node
|
||||
to this position with your own movement code. On the next ``physics_frame``, call
|
||||
Once the target has been set, the next position to follow in the path
|
||||
can be retrieved with the ``get_next_location()`` function. Move the parent actor node
|
||||
to this position with your own movement code. On the next ``physics_frame``, call
|
||||
``get_next_location()`` again for the next position and repeat this until the path ends.
|
||||
|
||||
NavigationAgents have their own internal logic to proceed with the current path and call for updates.
|
||||
NavigationAgents recognize by distance when a path point or the final target is reached.
|
||||
NavigationAgents refresh a path automatically when too far away from the current pathpoint.
|
||||
The important updates are all triggered with the ``get_next_location()`` function
|
||||
The important updates are all triggered with the ``get_next_location()`` function
|
||||
when called in ``_physics_process()``.
|
||||
|
||||
Be careful calling other NavigationAgent functions not required for path movement
|
||||
Be careful calling other NavigationAgent functions not required for path movement
|
||||
while the actor is following a path, as many function trigger a full path refresh.
|
||||
|
||||
.. note::
|
||||
|
||||
New NavigationAgents will automatically join the
|
||||
New NavigationAgents will automatically join the
|
||||
default navigation map for their 2D/3D dimension.
|
||||
|
||||
.. warning::
|
||||
@@ -68,8 +68,8 @@ They work well out of the box with :ref:`CharacterBody2D<class_CharacterBody2D>`
|
||||
NavigationAgent Avoidance
|
||||
-------------------------
|
||||
|
||||
This section explains how to use the built-in avoidance specific
|
||||
to NavigationAgent nodes. For general avoidance use and more technical details
|
||||
This section explains how to use the built-in avoidance specific
|
||||
to NavigationAgent nodes. For general avoidance use and more technical details
|
||||
on RVO avoidance see :ref:`doc_navigation_using_agent_avoidance`.
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ The following NavigationAgent properties are relevant for avoidance:
|
||||
- The property ``neighbor_distance`` controls the search radius of the agent when searching for other agents that should be avoided. A lower value reduces processing cost.
|
||||
- The property ``max_neighbors`` controls how many other agents are considered in the avoidance calculation if they all have overlapping radius.
|
||||
A lower value reduces processing cost but a too low value may result in agents ignoring the avoidance.
|
||||
- The property ``time_horizion`` controls the avoidance maneuver start and end distance.
|
||||
How early and for how long an agents reacts to other agents within the ``neighbor_distance`` radius to correct its own velocity.
|
||||
- The property ``time_horizion`` controls the avoidance maneuver start and end distance.
|
||||
How early and for how long an agents reacts to other agents within the ``neighbor_distance`` radius to correct its own velocity.
|
||||
A lower value results in avoidance kicking in with a very intense velocity change at a short distance while a high value results in very early but small velocity changes.
|
||||
- The property ``max_speed`` controls the maximum velocity assumed for the agents avoidance calculation.
|
||||
If the agents parents moves faster than this value the avoidance ``safe_velocity`` might not be accurate enough to avoid collision.
|
||||
@@ -99,12 +99,12 @@ The ``velocity_computed`` signal of the agent node must be connected to receive
|
||||
|
||||
Additional the current velocity of the agents parent must be set for the agent in ``_physics_process()`` with ``set_velocity()``.
|
||||
|
||||
After a short wait for processing the avoidance (still in the same frame) the ``safe_velocity`` vector will be received with the signal.
|
||||
After a short wait for processing the avoidance (still in the same frame) the ``safe_velocity`` vector will be received with the signal.
|
||||
This velocity vector should be used to move the NavigationAgent's parent node in order to avoidance collision with other avoidance registered agents in proximity.
|
||||
|
||||
RVO exists in its own space and has no information from navigation meshes or physics collision.
|
||||
Behind the scene avoidance agents are just circles with different radius on a flat plane.
|
||||
In narrow places obstructed with collision objects, the avoidance maneuver radius needs to be
|
||||
In narrow places obstructed with collision objects, the avoidance maneuver radius needs to be
|
||||
reduced considerably or disabled else the avoidance velocity will get actors stuck on collision easily.
|
||||
|
||||
.. note::
|
||||
@@ -113,19 +113,19 @@ reduced considerably or disabled else the avoidance velocity will get actors stu
|
||||
|
||||
.. warning::
|
||||
|
||||
Actors that move according to their avoidance agent velocity will not move at
|
||||
full speed, can leave the navigation mesh bounds and can make movement
|
||||
Actors that move according to their avoidance agent velocity will not move at
|
||||
full speed, can leave the navigation mesh bounds and can make movement
|
||||
pauses when the avoidance simulation becomes unsolvable.
|
||||
|
||||
Using the NavigationAgent ``enable_avoidance`` property is the preferred option
|
||||
to toggle avoidance but the following scripts for NavigationAgents can be
|
||||
Using the NavigationAgent ``enable_avoidance`` property is the preferred option
|
||||
to toggle avoidance but the following scripts for NavigationAgents can be
|
||||
used to create or delete avoidance callbacks for the agent RID.
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends NavigationAgent2D
|
||||
|
||||
|
||||
var agent : RID = get_rid()
|
||||
NavigationServer2D::get_singleton()->agent_set_callback(agent, self, "_avoidance_done")
|
||||
NavigationServer2D::get_singleton()->agent_set_callback(agent, null, "_avoidance_done")
|
||||
@@ -134,7 +134,7 @@ used to create or delete avoidance callbacks for the agent RID.
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends NavigationAgent3D
|
||||
|
||||
|
||||
var agent : RID = get_rid()
|
||||
NavigationServer3D::get_singleton()->agent_set_callback(agent, self, "_avoidance_done")
|
||||
NavigationServer3D::get_singleton()->agent_set_callback(agent, null, "_avoidance_done")
|
||||
@@ -192,14 +192,14 @@ This script adds basic navigation movement to a CharacterBody3D with a Navigatio
|
||||
navigation_agent.set_target_location(movement_target)
|
||||
|
||||
func _physics_process(delta):
|
||||
|
||||
|
||||
var next_path_position : Vector3 = navigation_agent.get_next_location()
|
||||
var current_agent_position : Vector3 = global_transform.origin
|
||||
var new_velocity : Vector3 = (next_path_position - current_agent_position).normalized() * movement_speed
|
||||
navigation_agent.set_velocity(new_velocity)
|
||||
|
||||
func _on_NavigationAgent3D_velocity_computed(safe_velocity : Vector3):
|
||||
# Move KinematicBody3D with the computed `safe_velocity` to avoid dynamic obstacles.
|
||||
# Move CharacterBody3D with the computed `safe_velocity` to avoid dynamic obstacles.
|
||||
velocity = safe_velocity
|
||||
move_and_slide()
|
||||
|
||||
@@ -220,12 +220,12 @@ This script adds basic navigation movement to a RigidBody3D with a NavigationAge
|
||||
navigation_agent.set_target_location(movement_target)
|
||||
|
||||
func _physics_process(delta):
|
||||
|
||||
|
||||
var next_path_position : Vector3 = navigation_agent.get_next_location()
|
||||
var current_agent_position : Vector3 = global_transform.origin
|
||||
var new_velocity : Vector3 = (next_path_position - current_agent_position).normalized() * velocity
|
||||
navigation_agent.set_velocity(new_velocity)
|
||||
|
||||
|
||||
func _on_NavigationAgent3D_velocity_computed(safe_velocity : Vector3):
|
||||
# Move RigidBody3D with the computed `safe_velocity` to avoid dynamic obstacles.
|
||||
set_linear_velocity(safe_velocity)
|
||||
|
||||
@@ -52,7 +52,7 @@ Most Godot nodes and resources contain these RIDs from the servers internally, a
|
||||
be obtained with different functions. In fact, anything that inherits :ref:`Resource <class_Resource>`
|
||||
can be directly casted to an RID. Not all resources contain an RID, though: in such cases, the RID will be empty. The resource can then be passed to server APIs as an RID.
|
||||
|
||||
.. Warning:: Resources are reference-counted (see :ref:`Reference <class_Reference>`), and
|
||||
.. Warning:: Resources are reference-counted (see :ref:`RefCounted <class_RefCounted>`), and
|
||||
references to a resource's RID are *not* counted when determining whether
|
||||
the resource is still in use. Make sure to keep a reference to the resource
|
||||
outside the server, or else both it and its RID will be erased.
|
||||
|
||||
@@ -271,5 +271,5 @@ moving. You can move them by updating the per-instance transform for each fish e
|
||||
doing so will be faster than moving thousands of MeshInstances per frame, it'll still likely be
|
||||
slow.
|
||||
|
||||
In the next tutorial we will cover how to use :ref:`Particles <class_Particles>` to take advantage
|
||||
In the next tutorial we will cover how to use :ref:`GPUParticles3D <class_GPUParticles3D>` to take advantage
|
||||
of the GPU and move each fish around individually while still receiving the benefits of instancing.
|
||||
|
||||
@@ -8,7 +8,7 @@ update their transform array. It is great for placing many static objects around
|
||||
scene. But it is still difficult to move the objects around the scene.
|
||||
|
||||
To make each instance move in an interesting way, we will use a
|
||||
:ref:`Particles <class_Particles>` node. Particles take advantage of GPU acceleration
|
||||
:ref:`GPUParticles3D <class_GPUParticles3D>` node. Particles take advantage of GPU acceleration
|
||||
by computing and setting the per-instance information in a :ref:`Shader <class_Shader>`.
|
||||
|
||||
.. note:: Particles are not available in GLES2, instead use :ref:`CPUParticles <class_CPUParticles>`,
|
||||
@@ -48,7 +48,7 @@ Then add the following two functions:
|
||||
return x;
|
||||
}
|
||||
|
||||
These functions come from the default :ref:`ParticlesMaterial <class_ParticlesMaterial>`.
|
||||
These functions come from the default :ref:`ParticleProcessMaterial <class_ParticleProcessMaterial>`.
|
||||
They are used to generate a random number from each particle's ``RANDOM_SEED``.
|
||||
|
||||
A unique thing about particle shaders is that some built-in variables are saved across frames.
|
||||
@@ -138,7 +138,7 @@ This code gives you the following behavior:
|
||||
|
||||
.. image:: img/scene.gif
|
||||
|
||||
Using a ParticlesMaterial you can make the fish behavior as simple or complex as you like. In this
|
||||
Using a ParticleProcessMaterial you can make the fish behavior as simple or complex as you like. In this
|
||||
tutorial we only set Velocity, but in your own Shaders you can also set ``COLOR``, rotation, scale
|
||||
(through ``TRANSFORM``). Please refer to the :ref:`Particles Shader Reference <doc_particle_shader>`
|
||||
for more information on particle shaders.
|
||||
|
||||
@@ -8,7 +8,7 @@ Physics
|
||||
physics_introduction
|
||||
rigid_body
|
||||
using_area_2d
|
||||
using_kinematic_body_2d
|
||||
using_character_body_2d
|
||||
ray-casting
|
||||
ragdoll_system
|
||||
kinematic_character_2d
|
||||
|
||||
@@ -56,7 +56,7 @@ or lose precision if the frame rate is too high or too low.
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
func _physics_process(delta):
|
||||
pass
|
||||
@@ -66,7 +66,7 @@ or lose precision if the frame rate is too high or too low.
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class PhysicsScript : KinematicBody2D
|
||||
public class PhysicsScript : CharacterBody2D
|
||||
{
|
||||
public override void _PhysicsProcess(float delta)
|
||||
{
|
||||
@@ -111,7 +111,7 @@ Moving the kinematic character
|
||||
Go back to the character scene, and open the script, the magic begins
|
||||
now! Kinematic body will do nothing by default, but it has a
|
||||
useful function called
|
||||
:ref:`KinematicBody2D.move_and_collide() <class_KinematicBody2D_method_move_and_collide>`.
|
||||
:ref:`CharacterBody2D.move_and_collide() <class_CharacterBody2D_method_move_and_collide>`.
|
||||
This function takes a :ref:`Vector2 <class_Vector2>` as
|
||||
an argument, and tries to apply that motion to the kinematic body. If a
|
||||
collision happens, it stops right at the moment of the collision.
|
||||
@@ -121,7 +121,7 @@ So, let's move our sprite downwards until it hits the floor:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
func _physics_process(delta):
|
||||
move_and_collide(Vector2(0, 1)) # Move down 1 pixel per physics frame
|
||||
@@ -131,7 +131,7 @@ So, let's move our sprite downwards until it hits the floor:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class PhysicsScript : KinematicBody2D
|
||||
public class PhysicsScript : CharacterBody2D
|
||||
{
|
||||
public override void _PhysicsProcess(float delta)
|
||||
{
|
||||
@@ -149,7 +149,7 @@ little more like a regular game character:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
const GRAVITY = 200.0
|
||||
var velocity = Vector2()
|
||||
@@ -165,7 +165,7 @@ little more like a regular game character:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class PhysicsScript : KinematicBody2D
|
||||
public class PhysicsScript : CharacterBody2D
|
||||
{
|
||||
const float gravity = 200.0f;
|
||||
Vector2 velocity;
|
||||
@@ -188,7 +188,7 @@ This adds basic support for walking when pressing left and right:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
const GRAVITY = 200.0
|
||||
const WALK_SPEED = 200
|
||||
@@ -216,7 +216,7 @@ This adds basic support for walking when pressing left and right:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class PhysicsScript : KinematicBody2D
|
||||
public class PhysicsScript : CharacterBody2D
|
||||
{
|
||||
const float gravity = 200.0f;
|
||||
const int walkSpeed = 200;
|
||||
|
||||
@@ -47,7 +47,7 @@ The other three bodies extend :ref:`PhysicsBody2D <class_PhysicsBody2D>`:
|
||||
``RigidBody2D`` directly, but instead you apply forces to it (gravity, impulses,
|
||||
etc.) and the physics engine calculates the resulting movement. :ref:`Read more about using rigid bodies. <doc_rigid_body>`
|
||||
|
||||
- :ref:`KinematicBody2D <class_KinematicBody2D>`
|
||||
- :ref:`CharacterBody2D <class_CharacterBody2D>`
|
||||
A body that provides collision detection, but no physics. All movement and
|
||||
collision response must be implemented in code.
|
||||
|
||||
@@ -233,16 +233,6 @@ A sleeping body acts like a static body, and its forces are not calculated by
|
||||
the physics engine. The body will wake up when forces are applied, either by
|
||||
a collision or via code.
|
||||
|
||||
Rigid body modes
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
A rigid body can be set to one of four modes:
|
||||
|
||||
- **Rigid** - The body behaves as a physical object. It collides with other bodies and responds to forces applied to it. This is the default mode.
|
||||
- **Static** - The body behaves like a :ref:`StaticBody2D <class_StaticBody2D>` and does not move.
|
||||
- **Character** - Similar to "Rigid" mode, but the body cannot rotate.
|
||||
- **Kinematic** - The body behaves like a :ref:`KinematicBody2D <class_KinematicBody2D>` and must be moved by code.
|
||||
|
||||
Using RigidBody2D
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -330,28 +320,28 @@ Contact monitoring via signals can be enabled via the :ref:`contact_monitor <cla
|
||||
property. See :ref:`RigidBody2D <class_RigidBody2D>` for the list of available
|
||||
signals.
|
||||
|
||||
KinematicBody2D
|
||||
CharacterBody2D
|
||||
---------------
|
||||
|
||||
:ref:`KinematicBody2D <class_KinematicBody2D>` bodies detect collisions with
|
||||
:ref:`CharacterBody2D <class_CharacterBody2D>` bodies detect collisions with
|
||||
other bodies, but are not affected by physics properties like gravity or friction.
|
||||
Instead, they must be controlled by the user via code. The physics engine will
|
||||
not move a kinematic body.
|
||||
not move a character body.
|
||||
|
||||
When moving a kinematic body, you should not set its ``position`` directly.
|
||||
When moving a character body, you should not set its ``position`` directly.
|
||||
Instead, you use the ``move_and_collide()`` or ``move_and_slide()`` methods.
|
||||
These methods move the body along a given vector, and it will instantly stop
|
||||
if a collision is detected with another body. After the body has collided,
|
||||
any collision response must be coded manually.
|
||||
|
||||
Kinematic collision response
|
||||
Character collision response
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
After a collision, you may want the body to bounce, to slide along a wall,
|
||||
or to alter the properties of the object it hit. The way you handle collision
|
||||
response depends on which method you used to move the KinematicBody2D.
|
||||
response depends on which method you used to move the CharacterBody2D.
|
||||
|
||||
:ref:`move_and_collide <class_KinematicBody2D_method_move_and_collide>`
|
||||
:ref:`move_and_collide <class_CharacterBody2D_method_move_and_collide>`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
When using ``move_and_collide()``, the function returns a
|
||||
@@ -365,7 +355,7 @@ occurred:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
var velocity = Vector2(250, 250)
|
||||
|
||||
@@ -376,7 +366,7 @@ occurred:
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
class Body : KinematicBody2D
|
||||
class Body : CharacterBody2D
|
||||
{
|
||||
private Vector2 _velocity = new Vector2(250, 250);
|
||||
|
||||
@@ -395,7 +385,7 @@ Or to bounce off of the colliding object:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
var velocity = Vector2(250, 250)
|
||||
|
||||
@@ -406,7 +396,7 @@ Or to bounce off of the colliding object:
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
class Body : KinematicBody2D
|
||||
class Body : CharacterBody2D
|
||||
{
|
||||
private Vector2 _velocity = new Vector2(250, 250);
|
||||
|
||||
@@ -418,7 +408,7 @@ Or to bounce off of the colliding object:
|
||||
}
|
||||
}
|
||||
|
||||
:ref:`move_and_slide <class_KinematicBody2D_method_move_and_slide>`
|
||||
:ref:`move_and_slide <class_CharacterBody2D_method_move_and_slide>`
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Sliding is a common collision response; imagine a player moving along walls
|
||||
@@ -437,7 +427,7 @@ the ground (including slopes) and jump when standing on the ground:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
var run_speed = 350
|
||||
var jump_speed = -1000
|
||||
@@ -465,7 +455,7 @@ the ground (including slopes) and jump when standing on the ground:
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
class Body : KinematicBody2D
|
||||
class Body : CharacterBody2D
|
||||
{
|
||||
private float _runSpeed = 350;
|
||||
private float _jumpSpeed = -1000;
|
||||
|
||||
@@ -79,7 +79,7 @@ You can also limit the simulation to only a few bones. To do so, pass the bone n
|
||||
Collision layer and mask
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Make sure to set up your collision layers and masks properly so the ``KinematicBody``'s capsule doesn't get in the way of the physics simulation:
|
||||
Make sure to set up your collision layers and masks properly so the ``CharacterBody3D``'s capsule doesn't get in the way of the physics simulation:
|
||||
|
||||
.. image:: img/ragdoll_layer.png
|
||||
|
||||
|
||||
@@ -163,13 +163,13 @@ as shown in the following image:
|
||||
|
||||
To avoid self-intersection, the ``intersect_ray()`` function can take an
|
||||
optional third parameter which is an array of exceptions. This is an
|
||||
example of how to use it from a KinematicBody2D or any other
|
||||
example of how to use it from a CharacterBody2D or any other
|
||||
collision object node:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
func _physics_process(delta):
|
||||
var space_state = get_world_2d().direct_space_state
|
||||
@@ -177,7 +177,7 @@ collision object node:
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
class Body : KinematicBody2D
|
||||
class Body : CharacterBody2D
|
||||
{
|
||||
public override void _PhysicsProcess(float delta)
|
||||
{
|
||||
@@ -202,7 +202,7 @@ member variable:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
func _physics_process(delta):
|
||||
var space_state = get_world().direct_space_state
|
||||
@@ -211,7 +211,7 @@ member variable:
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
class Body : KinematicBody2D
|
||||
class Body : CharacterBody2D
|
||||
{
|
||||
public override void _PhysicsProcess(float delta)
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ Here's the node setup for the coin:
|
||||
|
||||
To detect the overlap, we'll connect the appropriate signal on the Area2d. Which
|
||||
signal to use depends on the player's node type. If the player is another area,
|
||||
use ``area_entered``. However, let's assume our player is a ``KinematicBody2D``
|
||||
use ``area_entered``. However, let's assume our player is a ``CharacterBody2D``
|
||||
(and therefore a ``CollisionObject2D`` type), so we'll connect the
|
||||
``body_entered`` signal.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.. _doc_using_kinematic_body_2d:
|
||||
.. _doc_using_character_body_2d:
|
||||
|
||||
Using KinematicBody2D
|
||||
Using CharacterBody2D
|
||||
=====================
|
||||
|
||||
Introduction
|
||||
@@ -10,32 +10,32 @@ Godot offers several collision objects to provide both collision detection
|
||||
and response. Trying to decide which one to use for your project can be confusing.
|
||||
You can avoid problems and simplify development if you understand how each of them
|
||||
works and what their pros and cons are. In this tutorial, we'll look at the
|
||||
:ref:`KinematicBody2D <class_KinematicBody2D>` node and show some examples
|
||||
:ref:`CharacterBody2D <class_CharacterBody2D>` node and show some examples
|
||||
of how to use it.
|
||||
|
||||
.. note:: This document assumes you're familiar with Godot's various physics
|
||||
bodies. Please read :ref:`doc_physics_introduction` first.
|
||||
|
||||
What is a kinematic body?
|
||||
What is a character body?
|
||||
-------------------------
|
||||
|
||||
``KinematicBody2D`` is for implementing bodies that are controlled via code.
|
||||
Kinematic bodies detect collisions with other bodies when moving, but are not affected by
|
||||
``CharacterBody2D`` is for implementing bodies that are controlled via code.
|
||||
Character bodies detect collisions with other bodies when moving, but are not affected by
|
||||
engine physics properties, like gravity or friction. While this means that you
|
||||
have to write some code to create their behavior, it also means you have more
|
||||
precise control over how they move and react.
|
||||
|
||||
.. tip:: A `KinematicBody2D` can be affected by gravity and other forces,
|
||||
.. tip:: A `CharacterBody2D` can be affected by gravity and other forces,
|
||||
but you must calculate the movement in code. The physics engine will
|
||||
not move a `KinematicBody2D`.
|
||||
not move a `CharacterBody2D`.
|
||||
|
||||
Movement and collision
|
||||
----------------------
|
||||
|
||||
When moving a ``KinematicBody2D``, you should not set its ``position`` property
|
||||
When moving a ``CharacterBody2D``, you should not set its ``position`` property
|
||||
directly. Instead, you use the ``move_and_collide()`` or ``move_and_slide()`` methods.
|
||||
These methods move the body along a given vector and instantly stop if
|
||||
a collision is detected with another body. After a KinematicBody2D has collided,
|
||||
a collision is detected with another body. After a CharacterBody2D has collided,
|
||||
any *collision response* must be coded manually.
|
||||
|
||||
.. warning:: You should only do Kinematic body movement in the ``_physics_process()`` callback.
|
||||
@@ -129,7 +129,7 @@ and ``get_slide_collision()``:
|
||||
for i in get_slide_count():
|
||||
var collision = get_slide_collision(i)
|
||||
print("I collided with ", collision.collider.name)
|
||||
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
// Using MoveAndCollide.
|
||||
@@ -216,7 +216,7 @@ Movement and walls
|
||||
|
||||
If you've downloaded the sample project, this example is in "BasicMovement.tscn".
|
||||
|
||||
For this example, add a ``KinematicBody2D`` with two children: a ``Sprite2D`` and a
|
||||
For this example, add a ``CharacterBody2D`` with two children: a ``Sprite2D`` and a
|
||||
``CollisionShape2D``. Use the Godot "icon.png" as the Sprite2D's texture (drag it
|
||||
from the Filesystem dock to the *Texture* property of the ``Sprite2D``). In the
|
||||
``CollisionShape2D``'s *Shape* property, select "New RectangleShape2D" and
|
||||
@@ -224,12 +224,12 @@ size the rectangle to fit over the sprite image.
|
||||
|
||||
.. note:: See :ref:`doc_2d_movement` for examples of implementing 2D movement schemes.
|
||||
|
||||
Attach a script to the KinematicBody2D and add the following code:
|
||||
Attach a script to the CharacterBody2D and add the following code:
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
var speed = 250
|
||||
var velocity = Vector2()
|
||||
@@ -256,7 +256,7 @@ Attach a script to the KinematicBody2D and add the following code:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class KBExample : KinematicBody2D
|
||||
public class KBExample : CharacterBody2D
|
||||
{
|
||||
public int Speed = 250;
|
||||
private Vector2 _velocity = new Vector2();
|
||||
@@ -294,7 +294,7 @@ some obstacles. Add a :ref:`StaticBody2D <class_StaticBody2D>` with a
|
||||
rectangular collision shape. For visibility, you can use a sprite, a
|
||||
Polygon2D, or turn on "Visible Collision Shapes" from the "Debug" menu.
|
||||
|
||||
Run the scene again and try moving into the obstacle. You'll see that the ``KinematicBody2D``
|
||||
Run the scene again and try moving into the obstacle. You'll see that the ``CharacterBody2D``
|
||||
can't penetrate the obstacle. However, try moving into the obstacle at an angle and
|
||||
you'll find that the obstacle acts like glue - it feels like the body gets stuck.
|
||||
|
||||
@@ -325,7 +325,7 @@ uses the mouse pointer. Here is the code for the Player, using ``move_and_slide(
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
var Bullet = preload("res://Bullet.tscn")
|
||||
var speed = 200
|
||||
@@ -360,7 +360,7 @@ uses the mouse pointer. Here is the code for the Player, using ``move_and_slide(
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class KBExample : KinematicBody2D
|
||||
public class KBExample : CharacterBody2D
|
||||
{
|
||||
private PackedScene _bullet = (PackedScene)GD.Load("res://Bullet.tscn");
|
||||
public int Speed = 200;
|
||||
@@ -411,7 +411,7 @@ And the code for the Bullet:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
var speed = 750
|
||||
var velocity = Vector2()
|
||||
@@ -436,7 +436,7 @@ And the code for the Bullet:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class Bullet : KinematicBody2D
|
||||
public class Bullet : CharacterBody2D
|
||||
{
|
||||
public int Speed = 750;
|
||||
private Vector2 _velocity = new Vector2();
|
||||
@@ -498,7 +498,7 @@ Here's the code for the player body:
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
|
||||
extends KinematicBody2D
|
||||
extends CharacterBody2D
|
||||
|
||||
export (int) var run_speed = 100
|
||||
export (int) var jump_speed = -400
|
||||
@@ -533,7 +533,7 @@ Here's the code for the player body:
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class KBExample : KinematicBody2D
|
||||
public class KBExample : CharacterBody2D
|
||||
{
|
||||
[Export] public int RunSpeed = 100;
|
||||
[Export] public int JumpSpeed = -400;
|
||||
@@ -14,12 +14,12 @@ of bugs. There may be differences that are unintentional, but they should be rep
|
||||
Particles
|
||||
---------
|
||||
|
||||
GLES2 cannot use the :ref:`Particles <class_Particles>` or :ref:`Particles2D <class_Particles2D>` nodes
|
||||
GLES2 cannot use the :ref:`GPUParticles3D <class_GPUParticles3D>` or :ref:`GPUParticles2D <class_GPUParticles2D>` nodes
|
||||
as they require advanced GPU features. Instead, use :ref:`CPUParticles <class_CPUParticles>` or
|
||||
:ref:`CPUParticles2D <class_CPUParticles2D>`, which provides a similar interface to a
|
||||
:ref:`ParticlesMaterial <class_ParticlesMaterial>`.
|
||||
:ref:`ParticleProcessMaterial <class_ParticleProcessMaterial>`.
|
||||
|
||||
.. tip:: Particles and Particles2D can be converted to their CPU equivalent node with the "Convert to
|
||||
.. tip:: Particles and GPUParticles2D can be converted to their CPU equivalent node with the "Convert to
|
||||
CPUParticles" option in the editor.
|
||||
|
||||
``SCREEN_TEXTURE`` mip-maps
|
||||
|
||||
@@ -620,7 +620,7 @@ Use PascalCase for class and node names:
|
||||
|
||||
::
|
||||
|
||||
extends KinematicBody
|
||||
extends CharacterBody3D
|
||||
|
||||
Also use PascalCase when loading a class into a constant or a variable:
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ Type casting is a key concept in typed languages.
|
||||
Casting is the conversion of a value from one type to another.
|
||||
|
||||
Imagine an Enemy in your game, that ``extends Area2D``. You want it to
|
||||
collide with the Player, a ``KinematicBody2D`` with a script called
|
||||
collide with the Player, a ``CharacterBody2D`` with a script called
|
||||
``PlayerController`` attached to it. You use the ``on_body_entered``
|
||||
signal to detect the collision. With typed code, the body you detect is
|
||||
going to be a generic ``PhysicsBody2D``, and not your
|
||||
@@ -198,7 +198,7 @@ don't care about the node's type as long as it has the methods you need
|
||||
to call.
|
||||
|
||||
You can use casting to tell Godot the type you expect when you get a
|
||||
node: ``($Timer as Timer)``, ``($Player as KinematicBody2D)``, etc.
|
||||
node: ``($Timer as Timer)``, ``($Player as CharacterBody2D)``, etc.
|
||||
Godot will ensure the type works and if so, the line number will turn
|
||||
green at the left of the script editor.
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ There are two ways to load resources from code. First, you can use the ``load()`
|
||||
|
||||
func _ready():
|
||||
# Godot loads the Resource when it reads this very line.
|
||||
var imported_resource = load("res://robi.png")
|
||||
var imported_resource = load("res://robi.png")
|
||||
$sprite.texture = imported_resource
|
||||
|
||||
.. code-tab:: csharp
|
||||
@@ -165,7 +165,7 @@ This comes with many distinct advantages over alternative data
|
||||
structures, such as JSON, CSV, or custom TXT files. Users can only import these
|
||||
assets as a :ref:`Dictionary <class_Dictionary>` (JSON) or as a
|
||||
:ref:`File <class_File>` to parse. What sets Resources apart is their
|
||||
inheritance of :ref:`Object <class_Object>`, :ref:`Reference <class_Reference>`,
|
||||
inheritance of :ref:`Object <class_Object>`, :ref:`RefCounted <class_RefCounted>`,
|
||||
and :ref:`Resource <class_Resource>` features:
|
||||
|
||||
- They can define constants, so constants from other data fields or objects are not needed.
|
||||
@@ -210,7 +210,7 @@ Attach a script to it named ``bot_stats.gd`` (or just create a new script, and t
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
extends Resource
|
||||
|
||||
|
||||
@export var health : int
|
||||
@export var sub_resource : Resource
|
||||
@export var strings : PackedStringArray
|
||||
@@ -222,7 +222,7 @@ Attach a script to it named ``bot_stats.gd`` (or just create a new script, and t
|
||||
health = p_health
|
||||
sub_resource = p_sub_resource
|
||||
strings = p_strings
|
||||
|
||||
|
||||
.. code-tab:: csharp
|
||||
|
||||
// BotStats.cs
|
||||
@@ -252,9 +252,9 @@ Attach a script to it named ``bot_stats.gd`` (or just create a new script, and t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Now, create a :ref:`CharacterBody3D <class_CharacterBody3D>`, name it ``Bot``, and add the following script to it:
|
||||
|
||||
|
||||
.. tabs::
|
||||
.. code-tab:: gdscript GDScript
|
||||
extends CharacterBody3D
|
||||
@@ -265,9 +265,9 @@ Now, create a :ref:`CharacterBody3D <class_CharacterBody3D>`, name it ``Bot``, a
|
||||
# Uses an implicit, duck-typed interface for any 'health'-compatible resources.
|
||||
if stats:
|
||||
stats.health = 10
|
||||
print(stats.health)
|
||||
print(stats.health)
|
||||
# Prints "10"
|
||||
|
||||
|
||||
.. code-tab:: csharp
|
||||
// Bot.cs
|
||||
using System;
|
||||
@@ -287,7 +287,7 @@ Now, create a :ref:`CharacterBody3D <class_CharacterBody3D>`, name it ``Bot``, a
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Now, select the :ref:`CharacterBody3D <class_CharacterBody3D>` node which we named ``bot``, and drag&drop the ``bot_stats.tres`` resource onto the Inspector. It should print 10! Obviously, this setup can be used for more advanced features than this, but as long you really understand *how* it all worked, you should figure out everything else related to Resources.
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -8,7 +8,7 @@ Introduction
|
||||
|
||||
For the most common cases, Godot provides ready to use materials for
|
||||
most types of shaders, such as :ref:`StandardMaterial3D <class_StandardMaterial3D>`,
|
||||
:ref:`CanvasItemMaterial <class_CanvasItemMaterial>` and :ref:`ParticlesMaterial <class_ParticlesMaterial>`.
|
||||
:ref:`CanvasItemMaterial <class_CanvasItemMaterial>` and :ref:`ParticleProcessMaterial <class_ParticleProcessMaterial>`.
|
||||
They are flexible implementations that cover most use cases.
|
||||
|
||||
Shader materials allow writing a custom shader directly, for maximum flexibility.
|
||||
@@ -70,7 +70,7 @@ Converting to ShaderMaterial
|
||||
----------------------------
|
||||
|
||||
It is possible to convert from StandardMaterial3D, CanvasItemMaterial and
|
||||
ParticlesMaterial to ShaderMaterial. To do so, go to the material properties
|
||||
ParticleProcessMaterial to ShaderMaterial. To do so, go to the material properties
|
||||
and select the convert option.
|
||||
|
||||
.. image:: img/shader_material_convert.png
|
||||
|
||||
@@ -42,8 +42,8 @@ program (e.g. Blender). But Godot also has a few :ref:`PrimitiveMeshes
|
||||
importing Meshes.
|
||||
|
||||
There are multiple node types that you can use to draw a mesh. The main one is
|
||||
:ref:`MeshInstance <class_meshinstance>`, but you can also use :ref:`Particles
|
||||
<class_particles>`, :ref:`MultiMeshes <class_MultiMesh>` (with a
|
||||
:ref:`MeshInstance <class_meshinstance>`, but you can also use :ref:`GPUParticles3D
|
||||
<class_GPUParticles3D>`, :ref:`MultiMeshes <class_MultiMesh>` (with a
|
||||
:ref:`MultiMeshInstance <class_multimeshinstance>`), or others.
|
||||
|
||||
Typically, a material is associated with a given surface in a mesh, but some
|
||||
|
||||
Reference in New Issue
Block a user