added: units can now have their movement settings set through rpc
This commit is contained in:
@@ -2,9 +2,10 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Reset.Core.Tools;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Netcode;
|
||||
|
||||
namespace Reset.Units{
|
||||
public class UnitMovementHandler : MonoBehaviour{
|
||||
public class UnitMovementHandler : UnitComponent{
|
||||
[ShowInInspector, InlineProperty, HideLabel, FoldoutGroup("Resolved Movement", expanded: true)]
|
||||
public ResolvedMovement resolvedMovement;
|
||||
|
||||
@@ -207,11 +208,24 @@ namespace Reset.Units{
|
||||
// Setting absolute to true will cause the current gravity to snap to the new gravity value.
|
||||
// Keeping it false will make it apply additively to the current gravity. Both options use relativty for linear interpolation.
|
||||
public void SetNewGravity(float value, float relativity, bool absolute){ // new
|
||||
float newGravity;
|
||||
|
||||
if (absolute){
|
||||
resolvedMovement.gravity = Mathf.Lerp(resolvedMovement.gravity, value, relativity);
|
||||
newGravity = Mathf.Lerp(resolvedMovement.gravity, value, relativity);
|
||||
} else {
|
||||
resolvedMovement.gravity = Mathf.Lerp(resolvedMovement.gravity, resolvedMovement.gravity + value, relativity);
|
||||
newGravity = Mathf.Lerp(resolvedMovement.gravity, resolvedMovement.gravity + value, relativity);
|
||||
}
|
||||
|
||||
if (Unit.UnitIsNetworked() && !Unit.UnitIsLocal()) {
|
||||
SetNewGravityRpc(newGravity);
|
||||
} else {
|
||||
resolvedMovement.gravity = newGravity;
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
public void SetNewGravityRpc(float value){
|
||||
resolvedMovement.gravity = value;
|
||||
}
|
||||
|
||||
public void SetNewDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default, bool relativeToRotation = true){ // new
|
||||
@@ -223,31 +237,67 @@ namespace Reset.Units{
|
||||
relativeValue = relativeTo + value;
|
||||
}
|
||||
|
||||
if (absolute){
|
||||
resolvedMovement.moveDirection.World = Vector2.Lerp(resolvedMovement.moveDirection.World, relativeValue, relativity);
|
||||
} else {
|
||||
resolvedMovement.moveDirection.World = Vector2.Lerp(resolvedMovement.moveDirection.World, resolvedMovement.moveDirection.World + relativeValue, relativity);
|
||||
}
|
||||
|
||||
Debug.Log(resolvedMovement.moveDirection.World);
|
||||
}
|
||||
|
||||
public void SetNewRawDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default){ // new
|
||||
Vector2 relativeValue = relativeTo + value;
|
||||
Vector2 newValue;
|
||||
|
||||
if (absolute){
|
||||
resolvedMovement.moveDirection.RawWorld = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, relativeValue, relativity);
|
||||
newValue = Vector2.Lerp(resolvedMovement.moveDirection.World, relativeValue, relativity);
|
||||
} else {
|
||||
resolvedMovement.moveDirection.RawWorld = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, resolvedMovement.moveDirection.RawWorld + relativeValue, relativity);
|
||||
newValue = Vector2.Lerp(resolvedMovement.moveDirection.World, resolvedMovement.moveDirection.World + relativeValue, relativity);
|
||||
}
|
||||
|
||||
if (Unit.UnitIsNetworked() && !Unit.UnitIsLocal()) {
|
||||
SetNewDirectionRpc(newValue);
|
||||
} else {
|
||||
resolvedMovement.moveDirection.World = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
public void SetNewDirectionRpc(Vector2 value){
|
||||
resolvedMovement.moveDirection.World = value;
|
||||
}
|
||||
|
||||
public void SetNewRawDirection(Vector2 value, float relativity, bool absolute, Vector2 relativeTo = default){ // new
|
||||
Vector2 relativeValue = relativeTo + value;
|
||||
Vector2 newValue;
|
||||
|
||||
if (absolute){
|
||||
newValue = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, relativeValue, relativity);
|
||||
} else {
|
||||
newValue = Vector2.Lerp(resolvedMovement.moveDirection.RawWorld, resolvedMovement.moveDirection.RawWorld + relativeValue, relativity);
|
||||
}
|
||||
|
||||
if (Unit.UnitIsNetworked() && !Unit.UnitIsLocal()) {
|
||||
SetNewRawDirectionRpc(newValue);
|
||||
} else {
|
||||
resolvedMovement.moveDirection.RawWorld = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
public void SetNewRawDirectionRpc(Vector2 value){
|
||||
resolvedMovement.moveDirection.RawWorld = value;
|
||||
}
|
||||
|
||||
public void SetNewSpeed(float value, float relativity, bool absolute, float relativeTo = Mathf.Infinity){ // new
|
||||
float newSpeed;
|
||||
|
||||
if (absolute){
|
||||
resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, value, relativity);
|
||||
newSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, value, relativity);
|
||||
} else {
|
||||
resolvedMovement.moveSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, resolvedMovement.moveSpeed + value, relativity);
|
||||
newSpeed = Mathf.Lerp(resolvedMovement.moveSpeed, resolvedMovement.moveSpeed + value, relativity);
|
||||
}
|
||||
|
||||
if (Unit.UnitIsNetworked() && !Unit.UnitIsLocal()) {
|
||||
SetNewSpeedRpc(newSpeed);
|
||||
} else {
|
||||
resolvedMovement.moveSpeed = newSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
public void SetNewSpeedRpc(float value){
|
||||
resolvedMovement.moveSpeed = value;
|
||||
}
|
||||
|
||||
public void SetNewRotation(Vector3 value, float relativity, bool absolute, Vector3 relativeTo = default){ // new
|
||||
@@ -256,13 +306,25 @@ namespace Reset.Units{
|
||||
if (relativeTo != default) {
|
||||
valueAsQuaternion = Quaternion.LookRotation(relativeTo) * valueAsQuaternion;
|
||||
}
|
||||
|
||||
Quaternion newRotation;
|
||||
|
||||
if (absolute){
|
||||
resolvedMovement.rotation = Quaternion.Lerp(resolvedMovement.rotation, valueAsQuaternion, relativity);
|
||||
newRotation = Quaternion.Lerp(resolvedMovement.rotation, valueAsQuaternion, relativity);
|
||||
} else {
|
||||
resolvedMovement.rotation = Quaternion.Lerp(resolvedMovement.rotation, resolvedMovement.rotation * valueAsQuaternion, relativity);
|
||||
newRotation = Quaternion.Lerp(resolvedMovement.rotation, resolvedMovement.rotation * valueAsQuaternion, relativity);
|
||||
}
|
||||
|
||||
if (Unit.UnitIsNetworked() && !Unit.UnitIsLocal()) {
|
||||
SetNewRotationRpc(newRotation);
|
||||
} else {
|
||||
resolvedMovement.rotation = newRotation;
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Owner)]
|
||||
public void SetNewRotationRpc(Quaternion value){
|
||||
resolvedMovement.rotation = value;
|
||||
}
|
||||
|
||||
public void SetSpecifiedRotation(Vector3 inputRotation){
|
||||
|
||||
Reference in New Issue
Block a user