Skip to content

Commit

Permalink
Fix rotation lerp
Browse files Browse the repository at this point in the history
  • Loading branch information
warent committed Jul 10, 2024
1 parent 829c9ca commit e35efb9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions addons/HLNC/Serialization/NetworkScenesRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public partial class NetworkScenesRegister : Node

internal static Dictionary<byte, Dictionary<string, int>> NODE_PATHS_PACK = [];

/// <summary>
/// A map of every packed scene to a list of paths to its internal network nodes.
/// </summary>
internal static Dictionary<string, HashSet<string>> STATIC_NETWORK_NODE_PATHS = [];

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public void PhysicsProcess(double delta)
var lerpNode = wrapper.Node.GetNode(toLerp.Prop.NodePath);
if (toLerp.Weight < 1.0)
{
toLerp.Weight = Math.Min(toLerp.Weight + delta * 10, 1.0);
double result = -1;
if (lerpNode.HasMethod("NetworkLerp" + toLerp.Prop.Name))
{
Expand All @@ -250,7 +251,6 @@ public void PhysicsProcess(double delta)
if (result == -1)
{
// TODO: If this is too fast, it creates a jitter effect
toLerp.Weight = Math.Min(toLerp.Weight + delta * 10, 1.0);
if (toLerp.Prop.Type == Variant.Type.Quaternion)
{
var next_value = ((Quaternion)toLerp.From).Normalized().Slerp(((Quaternion)toLerp.To).Normalized(), (float)toLerp.Weight);
Expand Down
10 changes: 10 additions & 0 deletions addons/HLNC/Utilities/NetworkTransform.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Diagnostics;
using Godot;
using Godot.Collections;
Expand All @@ -6,6 +7,7 @@ namespace HLNC.Utilities
{
public partial class NetworkTransform : NetworkNode3D
{

public bool teleporting = true;

[Export]
Expand Down Expand Up @@ -99,6 +101,14 @@ public double NetworkLerpNetPosition(Variant from, Variant to, double weight)
return -1;
}

public double NetworkLerpNetRotation(Variant from, Variant to, double weight)
{
Vector3 start = from.AsVector3();
Vector3 end = to.AsVector3();
NetRotation = new Vector3((float)Mathf.LerpAngle(start.X, end.X, weight), (float)Mathf.LerpAngle(start.Y, end.Y, weight), (float)Mathf.LerpAngle(start.Z, end.Z, weight));
return weight;
}

public override void _PhysicsProcess(double delta)
{
base._PhysicsProcess(delta);
Expand Down
2 changes: 1 addition & 1 deletion addons/HLNC/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="HLNC"
description="Netcode Framework for Online Multiplayer Games"
author="Wyatt Arent"
version="0.4.0"
version="0.5.0"
script="plugin.gd"

0 comments on commit e35efb9

Please sign in to comment.