Hi, does someone know how to set the velocity on the airdrop planes? So far I've tried this:
Obviously I've tried different values for the vector but didn't seem to work.Code:void OnEntitySpawned(BaseNetworkable entity) { CargoPlane plane = entity.GetComponent<CargoPlane>(); if (plane == null) { return; } plane.SetVelocity(new UnityEngine.Vector3(0, 0, 3000)); } }
Solved Set cargoplane velocity
Discussion in 'Rust Development' started by DroneFW, Jun 1, 2015.
-
You normally just have to modify the secondsToTake field on the CargoPlane object.
Code:using System; using UnityEngine;public class CargoPlane : BaseEntity { private bool dropped; private Vector3 dropPosition = Vector3.zero; private Vector3 endPos; public SpawnFilter filter; public string prefabToDrop = "items/supply_drop"; private float secondsTaken; private float secondsToTake; private Vector3 startPos; private void Update() { if (base.isServer) { this.secondsTaken += Time.deltaTime; float t = Mathf.InverseLerp(0f, this.secondsToTake, this.secondsTaken); if (!this.dropped && (t >= 0.5f)) { this.dropped = true; BaseEntity entity = GameManager.server.CreateEntity(this.prefabToDrop, base.transform.position, new Quaternion(), true); if (entity != null) { entity.globalBroadcast = true; entity.Spawn(true); } } base.transform.position = Vector3.Lerp(this.startPos, this.endPos, t); base.TransformChanged(); if (t >= 1f) { base.SendMessage("KillMessage", SendMessageOptions.DontRequireReceiver); } } } }
-
-
-
How would I set the secondsToTake field, as it's private?
-
Something like this (untested):
Code:... FieldInfo secondsToTake = typeof(CargoPlane).GetField("secondsToTake", BindingFlags.NonPublic | BindingFlags.Instance); ... void OnEntitySpawned(BaseNetworkable entity) { var plane = entity as CargoPlane; if (plane == null) return; var secsToTake = secondsToTake.GetValue(plane); Puts($"It will take the plane {secsToTake}s"); secondsToTake.SetValue(plane, 100f); } ...
-