27 lines
713 B
C#
27 lines
713 B
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class move : Node3D
|
|
{
|
|
// 移动速度变量,可以在编辑器中调整
|
|
[Export]
|
|
public float MoveSpeed = 2.0f;
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
}
|
|
|
|
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
public override void _Process(double delta)
|
|
{
|
|
// 将double类型的delta转换为float,便于计算
|
|
float deltaf = (float)delta;
|
|
|
|
// 创建Z轴正方向的移动向量
|
|
Vector3 movement = -Vector3.Forward * MoveSpeed * deltaf;
|
|
|
|
// 应用移动
|
|
Translate(movement);
|
|
}
|
|
} |