[мод] itemphysic full для майнкрафт

KinematicBody2D¶

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.

When moving a kinematic body, you should not set its directly.
Instead, you use the or 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

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.

When using , the function returns a
object, which contains
information about the collision and the colliding body. You can use this
information to determine the response.

For example, if you want to find the point in space where the collision
occurred:

GDScript

C#

Or to bounce off of the colliding object:

GDScript

C#

Sliding is a common collision response; imagine a player moving along walls
in a top-down game or running up and down slopes in a platformer. While it’s
possible to code this response yourself after using ,
provides a convenient way to implement sliding movement
without writing much code.

Предупреждение

automatically includes the timestep in its
calculation, so you should not multiply the velocity vector
by .

For example, use the following code to make a character that can walk along
the ground (including slopes) and jump when standing on the ground:

GDScript

C#

See for more details on using ,
including a demo project with detailed code.

RigidBody2D¶

This is the node that implements simulated 2D physics. You do not control a
directly. Instead, you apply forces
to it and the physics engine calculates the resulting movement, including
collisions with other bodies, and collision responses, such as bouncing,
rotating, etc.

You can modify a rigid body’s behavior via properties such as «Mass»,
«Friction», or «Bounce», which can be set in the Inspector.

The body’s behavior is also affected by the world’s properties, as set in
Project Settings -> Physics, or by entering an
that is overriding the global physics properties.

When a rigid body is at rest and hasn’t moved for a while, it goes to sleep.
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 and does not move.

  • Character — Similar to «Rigid» mode, but the body cannot rotate.

  • Kinematic — The body behaves like a and must be moved by code.

Using RigidBody2D

One of the benefits of using a rigid body is that a lot of behavior can be had
«for free» without writing any code. For example, if you were making an
«Angry Birds»-style game with falling blocks, you would only need to create
RigidBody2Ds and adjust their properties. Stacking, falling, and bouncing would
automatically be calculated by the physics engine.

However, if you do wish to have some control over the body, you should take
care — altering the , , or other physics properties
of a rigid body can result in unexpected behavior. If you need to alter any
of the physics-related properties, you should use the
callback instead of . In this callback, you have access
to the body’s ,
which allows for safely changing properties and synchronizing them with
the physics engine.

For example, here is the code for an «Asteroids» style spaceship:

GDScript

C#

Note that we are not setting the or
properties directly, but rather applying forces ( and ) to
the body and letting the physics engine calculate the resulting movement.

Примечание

When a rigid body goes to sleep, the
function will not be called. To override this behavior, you will
need to keep the body awake by creating a collision, applying a
force to it, or by disabling the
property. Be aware that this can have a negative effect on performance.

Collision objects¶

Godot offers four kinds of physics bodies, extending :

Area2D

Area2D nodes provide detection and influence. They can detect when
objects overlap and can emit signals when bodies enter or exit. An Area2D
can also be used to override physics properties, such as gravity or damping,
in a defined area.

The other three bodies extend :

  • A static body is one that is not moved by the physics engine. It participates
    in collision detection, but does not move in response to the collision. They
    are most often used for objects that are part of the environment or that do
    not need to have any dynamic behavior.

  • This is the node that implements simulated 2D physics. You do not control a
    directly, but instead you apply forces to it (gravity, impulses,
    etc.) and the physics engine calculates the resulting movement.

  • A body that provides collision detection, but no physics. All movement and
    collision response must be implemented in code.

Physics material

Static bodies and rigid bodies can be configured to use a . This allows adjusting the friction and bounce of an object,
and set if it’s absorbent and/or rough.

Виды и формы коллизий (столкновений)

A physics body can hold any number of objects
as children. These shapes are used to define the object’s collision bounds
and to detect contact with other objects.

Примечание

In order to detect collisions, at least one must be
assigned to the object.

The most common way to assign a shape is by adding a
or as a child of the object.
These nodes allow you to draw the shape directly in the editor workspace.

Важно

Be careful to never scale your collision shapes in the editor.
The «Scale» property in the Inspector should remain . When changing
the size of the collision shape, you should always use the size handles, not
the scale handles. Scaling a shape can result in unexpected
collision behavior.

Physics process callback

The physics engine may spawn multiple threads to improve performance, so
it can use up to a full frame to process physics. Because of this, the value
of a body’s state variables such as or
may not be accurate for the current frame.

In order to avoid this inaccuracy, any code that needs to access a body’s properties should
be run in the
callback, which is called before each physics step at a constant frame rate
(60 times per second by default). This method will be passed a
parameter, which is a floating-point number equal to the time passed in
seconds since the last step. When using the default 60 Hz physics update rate,
it will typically be equal to (but not always, see below).

Примечание

It’s recommended to always use the parameter when relevant in your
physics calculations, so that the game behaves correctly if you change the
physics update rate or if the player’s device can’t keep up.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Adblock
detector