mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
Update some C# examples for 4.0 (#6693)
* Update some C# examples - Rename members that have been renamed in Godot's C# API for 4.0. - Change `delta` parameter type to `double`. - Ensure parameters match base declaration. - Other minor code fixes. --------- Co-authored-by: Paul Joannon <437025+paulloz@users.noreply.github.com>
This commit is contained in:
@@ -219,9 +219,9 @@ Let's do an example with the following pseudocode:
|
||||
|
||||
private float _t = 0.0f;
|
||||
|
||||
public override void _Process(float delta)
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_t += delta;
|
||||
_t += (float)delta;
|
||||
Position = CubicBezier(p0, p1, p2, p3, _t);
|
||||
}
|
||||
|
||||
@@ -268,9 +268,9 @@ Traversal at constant speed, then, can be done with the following pseudo-code:
|
||||
|
||||
private float _t = 0.0f;
|
||||
|
||||
public override void _Process(float delta)
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_t += delta;
|
||||
_t += (float)delta;
|
||||
Position = curve.InterpolateBaked(_t * curve.GetBakedLength(), true);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,9 @@ Here is example pseudo-code for going from point A to B using interpolation:
|
||||
|
||||
private float _t = 0.0f;
|
||||
|
||||
public override void _PhysicsProcess(float delta)
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_t += delta * 0.4f;
|
||||
_t += (float)delta * 0.4f;
|
||||
|
||||
Marker2D a = GetNode<Marker2D>("A");
|
||||
Marker2D b = GetNode<Marker2D>("B");
|
||||
@@ -90,9 +90,9 @@ Using the following pseudocode:
|
||||
|
||||
private float _t = 0.0f;
|
||||
|
||||
public override void _PhysicsProcess(float delta)
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_t += delta;
|
||||
_t += (float)delta;
|
||||
|
||||
Marker3D p1 = GetNode<Marker3D>("Position1");
|
||||
Marker3D p2 = GetNode<Marker3D>("Position2");
|
||||
@@ -125,13 +125,13 @@ Interpolation can be used to smooth movement, rotation, etc. Here is an example
|
||||
|
||||
private const float FollowSpeed = 4.0f;
|
||||
|
||||
public override void _PhysicsProcess(float delta)
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
Vector2 mousePos = GetLocalMousePosition();
|
||||
|
||||
Sprite2D sprite = GetNode<Sprite2D>("Sprite2D");
|
||||
|
||||
sprite.Position = sprite.Position.Lerp(mousePos, delta * FollowSpeed);
|
||||
sprite.Position = sprite.Position.Lerp(mousePos, (float)delta * FollowSpeed);
|
||||
}
|
||||
|
||||
Here is how it looks:
|
||||
|
||||
@@ -170,9 +170,9 @@ Here's how that would be done in code (place the script on a Node2D):
|
||||
|
||||
float rot = 0.5f; // The rotation to apply.
|
||||
Transform2D t = Transform2D.Identity;
|
||||
t.x.x = t.y.y = Mathf.Cos(rot);
|
||||
t.x.y = t.y.x = Mathf.Sin(rot);
|
||||
t.y.x *= -1;
|
||||
t.X.X = t.Y.Y = Mathf.Cos(rot);
|
||||
t.X.Y = t.Y.X = Mathf.Sin(rot);
|
||||
t.Y.X *= -1;
|
||||
Transform = t; // Change the node's transform to what we calculated.
|
||||
|
||||
To calculate the object's rotation from an existing transformation
|
||||
@@ -265,15 +265,15 @@ you to try and reproduce the screenshot without looking at the code!
|
||||
|
||||
Transform2D t = Transform2D.Identity;
|
||||
// Translation
|
||||
t.origin = new Vector2(350, 150);
|
||||
t.Origin = new Vector2(350, 150);
|
||||
// Rotation
|
||||
float rot = -0.5f; // The rotation to apply.
|
||||
t.x.x = t.y.y = Mathf.Cos(rot);
|
||||
t.x.y = t.y.x = Mathf.Sin(rot);
|
||||
t.y.x *= -1;
|
||||
t.X.X = t.Y.Y = Mathf.Cos(rot);
|
||||
t.X.Y = t.Y.X = Mathf.Sin(rot);
|
||||
t.Y.X *= -1;
|
||||
// Scale
|
||||
t.x *= 3;
|
||||
t.y *= 3;
|
||||
t.X *= 3;
|
||||
t.Y *= 3;
|
||||
Transform = t; // Change the node's transform to what we calculated.
|
||||
|
||||
Shearing the transformation matrix (advanced)
|
||||
@@ -435,7 +435,7 @@ This code moves an object 100 units to its own right:
|
||||
.. code-tab:: csharp
|
||||
|
||||
Transform2D t = Transform;
|
||||
t.origin += t.x * 100;
|
||||
t.Origin += t.X * 100;
|
||||
Transform = t;
|
||||
|
||||
For moving in 3D, you would need to replace "x" with "basis.x".
|
||||
@@ -500,11 +500,11 @@ the code we would use:
|
||||
|
||||
// Calculate the child's world space transform
|
||||
// origin = (2, 0) * 100 + (0, 1) * 100 + (100, 200)
|
||||
Vector2 origin = parent.x * child.origin.x + parent.y * child.origin.y + parent.origin;
|
||||
Vector2 origin = parent.X * child.Origin.X + parent.Y * child.Origin.Y + parent.Origin;
|
||||
// basisX = (2, 0) * 0.5 + (0, 1) * 0 = (0.5, 0)
|
||||
Vector2 basisX = parent.x * child.x.x + parent.y * child.x.y;
|
||||
Vector2 basisX = parent.X * child.X.X + parent.Y * child.X.Y;
|
||||
// basisY = (2, 0) * 0 + (0, 1) * 0.5 = (0.5, 0)
|
||||
Vector2 basisY = parent.x * child.y.x + parent.y * child.y.y;
|
||||
Vector2 basisY = parent.X * child.Y.X + parent.Y * child.Y.Y;
|
||||
|
||||
// Change the node's transform to what we calculated.
|
||||
Transform = new Transform2D(basisX, basisY, origin);
|
||||
|
||||
@@ -468,6 +468,6 @@ terrain. Godot provides :ref:`class_fastnoiselite` for this, which supports
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GD.Print(_noise.GetNoise1d(i));
|
||||
GD.Print(_noise.GetNoise1D(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ The individual components of the vector can be accessed directly by name.
|
||||
var a = new Vector2(2, 5);
|
||||
// create a vector and assign x and y manually
|
||||
var b = new Vector2();
|
||||
b.x = 3;
|
||||
b.y = 1;
|
||||
b.X = 3;
|
||||
b.Y = 1;
|
||||
|
||||
Adding vectors
|
||||
--------------
|
||||
@@ -345,9 +345,9 @@ The cross product is calculated like this:
|
||||
.. code-tab:: csharp
|
||||
|
||||
var c = new Vector3();
|
||||
c.x = (a.y * b.z) - (a.z * b.y);
|
||||
c.y = (a.z * b.x) - (a.x * b.z);
|
||||
c.z = (a.x * b.y) - (a.y * b.x);
|
||||
c.X = (a.Y * b.Z) - (a.Z * b.Y);
|
||||
c.Y = (a.Z * b.X) - (a.X * b.Z);
|
||||
c.Z = (a.X * b.Y) - (a.Y * b.X);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user