0 of 0

File information

Last updated

Original upload

Created by

Ebediam

Uploaded by

Ebediam

Virus scan

Safe to use

Tags for this mod

About this mod

A friend asked me to add the Power Pole from Dragon Ball, so here it is! Press trigger to make it grow and the action button to shrink it. Press both at the same time to freeze the pole in place, so you can use it to climb!

Permissions and credits
Changelogs
Known issues:

-The pole grows in both sides, so it becomes quite difficult to handle if it's long enough

-Due to hand sliding, you can end up with your hand outside of the pole itself when shrinking it.

-Even though the handle is there, for some fucking reason you can't access it if you're far enough from the center of the pole.


Here's the code.   

  public class ItemPowerPole : MonoBehaviour
    {
        protected Item item;
        private Transform poleTransform;


        private Transform meshTransform;
        private Transform colliderTransform;

        private Transform tipTransform;
        private Transform bottomTransform;

        private Vector3 orientation;

        private float growthSpeed = 0.05f;
        private float shrinkMultiplier = 1f;

        private float minPoleLength = 0.2f;

        private float colliderGrowthStep;
        private float meshGrowthStep;

        private bool isGrowing = false;
        private bool isShrinking = false;
        private bool trigger = false;
        private bool button = false;
        public bool scaleable = true;

        protected void Awake()
        {

            item = this.GetComponent<Item>();
            poleTransform = item.transform;
            meshTransform = poleTransform.Find("Mesh");


            colliderTransform = poleTransform.Find("Collider");

            colliderGrowthStep = colliderTransform.localScale.y * growthSpeed;
            meshGrowthStep = meshTransform.localScale.y * growthSpeed;



            tipTransform = item.definition.GetCustomReference("TipTransform");
            bottomTransform = item.definition.GetCustomReference("BottomTransform");

            item.OnUngrabEvent += OnPoleUngrabEvent;
            item.OnHeldActionEvent += OnPoleHeldAction;



        }

        void OnPoleHeldAction(Interactor interactor, Handle handle, Interactable.Action action)
        {

            if (action == Interactable.Action.UseStart)
            {
                    trigger = true;

                if (trigger && button)
                {
                    Freeze();
                }
                else
                {
                    isGrowing = true;
                }


            }
            if (action == Interactable.Action.AlternateUseStart)
            {
                button = true;
                if (trigger && button)
                {
                    Freeze();
                }
                else
                {
                    isShrinking = true;
                }

            }




            if (action == Interactable.Action.UseStop)
            {
                isGrowing = false;
                trigger = false;
            }

            if (action == Interactable.Action.AlternateUseStop)
            {
                isShrinking = false;
                button = false;

            }


        }

        
        void OnPoleUngrabEvent(Handle handle, Interactor interactor, bool throwing)
        {
            trigger = false;
            button = false;
        }

        void FixedUpdate()
        {
            if (isGrowing && scaleable)
            {
                Grow(1f);
            }

            if (isShrinking & scaleable)
            {
                Grow(-1*shrinkMultiplier);
            }


        }

        void Grow(float speed)
        {
            orientation = tipTransform.position - bottomTransform.position;
            orientation.Normalize();
            if (Vector3.Distance(tipTransform.position+orientation*speed*meshGrowthStep, bottomTransform.position-orientation* speed*meshGrowthStep) > minPoleLength)
            {
                meshTransform.localScale += new Vector3(0f, meshGrowthStep*speed, 0f);
                colliderTransform.localScale += new Vector3(0f, colliderGrowthStep*speed, 0f);
                tipTransform.position += orientation *meshGrowthStep* speed;
                bottomTransform.position -= orientation *meshGrowthStep* speed;
                item.handles[0].definition.axisLength = Vector3.Distance(tipTransform.position, bottomTransform.position);
                item.handles[0].data.highlighterShowAxisLine = true;
                item.handles[0].disableProximityHighlighter = false;
                item.handles[0].data.Refresh();
            }
        }

        void Freeze()
        {
            scaleable = !scaleable;
            item.rb.isKinematic = !item.rb.isKinematic;
            trigger = false;
            button = false;
        }
    }