WIP: Add rust logic for the plater physics
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is running
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is running
This commit is contained in:
parent
221734d8c7
commit
6622a143c8
@ -1,31 +1,7 @@
|
||||
use godot::prelude::*;
|
||||
use godot::classes::Sprite2D;
|
||||
use godot::classes::ISprite2D;
|
||||
struct MyExtension;
|
||||
|
||||
mod player;
|
||||
|
||||
#[gdextension]
|
||||
unsafe impl ExtensionLibrary for MyExtension {}
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Sprite2D)]
|
||||
struct Player {
|
||||
speed: f64,
|
||||
angular_speed: f64,
|
||||
|
||||
base: Base<Sprite2D>
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl ISprite2D for Player {
|
||||
fn init(base: Base<Sprite2D>) -> Self {
|
||||
godot_print!("Hello, world!"); // Prints to the Godot console
|
||||
|
||||
Self {
|
||||
speed: 400.0,
|
||||
angular_speed: std::f64::consts::PI,
|
||||
base,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -1,2 +1,2 @@
|
||||
mod server_node;
|
||||
mod client_node;
|
||||
mod server_node;
|
||||
|
@ -15,10 +15,10 @@ const JUMP_VELOCITY: f32 = 4.5;
|
||||
const SPEED: f32 = 5.0;
|
||||
|
||||
#[godot_api]
|
||||
impl ICharacterBody3D for PlayerServerNode{
|
||||
impl ICharacterBody3D for PlayerServerNode {
|
||||
fn init(base: Base<CharacterBody3D>) -> Self {
|
||||
Self {
|
||||
base,
|
||||
base,
|
||||
jumping: false,
|
||||
input_direction: Vector2::new(0.0, 0.0),
|
||||
input_rotation: Vector3::new(0.0, 0.0, 0.0),
|
||||
@ -33,7 +33,7 @@ impl ICharacterBody3D for PlayerServerNode{
|
||||
let new_velocity = self.base().get_velocity() + new_gravity;
|
||||
self.base_mut().set_velocity(new_velocity);
|
||||
}
|
||||
|
||||
|
||||
if self.base().is_on_floor() && self.jumping {
|
||||
let mut new_velocity = self.base().get_velocity();
|
||||
new_velocity.y = JUMP_VELOCITY;
|
||||
@ -42,7 +42,8 @@ impl ICharacterBody3D for PlayerServerNode{
|
||||
self.jumping = false;
|
||||
|
||||
if self.base().is_on_floor() {
|
||||
let direction = self.base().get_transform().basis * Vector3::new(self.input_direction.x, 0.0, self.input_direction.y);
|
||||
let direction = self.base().get_transform().basis
|
||||
* Vector3::new(self.input_direction.x, 0.0, self.input_direction.y);
|
||||
if direction.length() > 0.0 {
|
||||
let direction = direction.normalized();
|
||||
let new_velocity = Vector3::new(
|
||||
@ -52,14 +53,14 @@ impl ICharacterBody3D for PlayerServerNode{
|
||||
);
|
||||
self.base_mut().set_velocity(new_velocity);
|
||||
} else {
|
||||
let moved = self.base().get_velocity().clone().move_toward(Vector3::new(0.0, 0.0, 0.0), SPEED);
|
||||
let new_velocity = Vector3::new(
|
||||
moved.x,
|
||||
self.base().get_velocity().y,
|
||||
moved.z,
|
||||
);
|
||||
let moved = self
|
||||
.base()
|
||||
.get_velocity()
|
||||
.clone()
|
||||
.move_toward(Vector3::new(0.0, 0.0, 0.0), SPEED);
|
||||
let new_velocity = Vector3::new(moved.x, self.base().get_velocity().y, moved.z);
|
||||
self.base_mut().set_velocity(new_velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.base_mut().move_and_slide();
|
||||
@ -84,7 +85,7 @@ impl PlayerServerNode {
|
||||
new_rotation.x = x;
|
||||
self.base_mut().set_rotation(new_rotation);
|
||||
}
|
||||
|
||||
|
||||
#[rpc(any_peer, call_local, unreliable_ordered)]
|
||||
fn set_rotation_y(&mut self, y: f32) {
|
||||
let mut new_rotation = self.base().get_rotation();
|
||||
|
Loading…
x
Reference in New Issue
Block a user