as the title says, when the airdrop lands, it still acts like its falling, so it just slides on away.
Constantly slides away once landed
Yes, that is very annoying! Otherwise it's great and makes it realistic but the drop shouldn't move so long after landing or sliding up a hill
Thanks to Steenamarro for the help!
using UnityEngine;
using Newtonsoft.Json;
using System.Collections.Generic;
using Oxide.Core.Libraries.Covalence;
using System;
namespace Oxide.Plugins
{
[Info("Windy Airdrop", "Colon Blow", "1.0.2")] // Slidy fix
[Description("Airdrops move some as if its windy")]
public class WindyAirdrop : CovalencePlugin
{
//Rust update fixes
#region Load
private bool initComplete = false;
private void OnServerInitialized()
{
initComplete = true;
}
#endregion
#region Configuration
private static PluginConfig config;
private class PluginConfig
{
public WindyAirdropSettings windyAirdropSettings { get; set; }
public class WindyAirdropSettings
{
[JsonProperty(PropertyName = "Wind Speed Max - Maximus wind speed : ")] public float windspeedMax { get; set; }
[JsonProperty(PropertyName = "Wind Speed Min - Minimum wind speed : ")] public float windspeedMin { get; set; }
}
public static PluginConfig DefaultConfig() => new PluginConfig()
{
windyAirdropSettings = new PluginConfig.WindyAirdropSettings
{
windspeedMax = 5f,
windspeedMin = 1f,
}
};
}
protected override void LoadDefaultConfig()
{
PrintWarning("New configuration file created!!");
config = PluginConfig.DefaultConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<PluginConfig>();
SaveConfig();
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
#endregion
#region Hooks
private void OnEntitySpawned(SupplyDrop supplyDrop)
{
if (!initComplete) return;
var windModifier = supplyDrop.gameObject.AddComponent<SupplyDropModifier>();
}
#endregion
#region SupplyDrop Wind
private class SupplyDropModifier : MonoBehaviour
{
WindyAirdrop.PluginConfig.WindyAirdropSettings airdropSettings = new PluginConfig.WindyAirdropSettings();
SupplyDrop supplyDrop;
Vector3 windDir;
Vector3 newDir;
float windSpeed;
int counter;
int nextwind;
bool dropinit = false;
float y = 1000;
private void Awake()
{
airdropSettings = config.windyAirdropSettings;
if (airdropSettings == null) { OnDestroy(); return; }
supplyDrop = GetComponent<SupplyDrop>();
if (supplyDrop == null) { OnDestroy(); return; }
windDir = GetDirection();
windSpeed = UnityEngine.Random.Range(airdropSettings.windspeedMin, airdropSettings.windspeedMax);
counter = 0;
nextwind = UnityEngine.Random.Range(100, 1000);
dropinit = true;
}
private Vector3 GetDirection()
{
var direction = UnityEngine.Random.insideUnitSphere * 5f;
if (direction.y > -windSpeed) direction.y = -windSpeed;
return direction;
}
private void FixedUpdate()
{
if (!dropinit) return;
if (supplyDrop == null || supplyDrop.transform.position.y >= y)
{
OnDestroy();
return;
}
y = supplyDrop.transform.position.y;
newDir = Vector3.RotateTowards(transform.forward, windDir, 0.5f * Time.deltaTime, 0.0F);
newDir.y = 0f;
supplyDrop.transform.position = Vector3.MoveTowards(transform.position, transform.position + windDir, (windSpeed) * Time.deltaTime);
supplyDrop.transform.rotation = Quaternion.LookRotation(newDir);
if (counter == nextwind) { windDir = GetDirection(); counter = 0; nextwind = UnityEngine.Random.Range(100, 1000); }
counter++;
}
private void OnDestroy()
{
GameObject.Destroy(this);
}
}
void OnSupplyDropLanded(SupplyDrop entity)
{
var comp = entity.GetComponent<SupplyDropModifier>();
if (comp != null)
UnityEngine.Object.Destroy(comp);
}
#endregion
}