Thread: Buildsystem/"Gravitygun" problems

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Feb 2016
    Location
    Germany
    Posts
    146

    Buildsystem/"Gravitygun" problems

    Hi!

    For another buildsystem i am experimenting with i have scripted a "Gravitygun".

    Code:
    void PrimaryAttack()
        {
            // Throw
            if(eHeld !is null)
            {
                g_Game.AlertMessage( at_console, "Now throwing: " + eHeld.pev.classname + "\n" );
                Vector vecToEntity = (m_pPlayer.pev.origin - eHeld.pev.origin).Normalize();    
                eHeld.pev.velocity = -vecToEntity * shootForce;
                eHeld.pev.movetype = MOVETYPE_TOSS;
                @eHeld = null;
                self.m_flNextSecondaryAttack = g_Engine.time + 0.5;
            }
            // Shoot
            else
            {
                TraceResult tr;
    
                Math.MakeVectors( m_pPlayer.pev.v_angle );
                Vector vecSrc    = m_pPlayer.GetGunPosition();
                Vector vecEnd    = vecSrc + g_Engine.v_forward * maxGrabDistance;
    
                g_Utility.TraceLine( vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer.edict(), tr );
    
                if ( tr.flFraction >= 1.0 )
                {
                
                }
                else
                {
                    CBaseEntity@ eGrab = g_EntityFuncs.Instance( tr.pHit );
                    
                    if(eGrab !is null)
                    {
                        
                        g_Game.AlertMessage( at_console, "Grabbing shooting: " + eGrab.pev.classname + "\n" );
                        
                        if(eGrab.pev.ClassNameIs("gsf_box") || eGrab.pev.ClassNameIs("gsf_3x2"))
                        {
                            Vector vecToEntity = (m_pPlayer.pev.origin - eGrab.pev.origin).Normalize();    
                            eGrab.pev.velocity = -vecToEntity * shootForce;
                            self.m_flNextSecondaryAttack = g_Engine.time + 0.5;
                        }
                    }
                }
            }
        }
        
        void SecondaryAttack()
        {
            // Drop
            if(eHeld !is null)
            {
                g_Game.AlertMessage( at_console, "Now dropping: " + eHeld.pev.classname + "\n" );
                eHeld.pev.movetype = MOVETYPE_TOSS;
                @eHeld = null;
                self.m_flNextSecondaryAttack = g_Engine.time + 0.5;
            }
            // Grab
            else
            {
                TraceResult tr;
    
                Math.MakeVectors( m_pPlayer.pev.v_angle );
                Vector vecSrc    = m_pPlayer.GetGunPosition();
                Vector vecEnd    = vecSrc + g_Engine.v_forward * maxGrabDistance;
    
                g_Utility.TraceLine( vecSrc, vecEnd, dont_ignore_monsters, m_pPlayer.edict(), tr );
    
                if ( tr.flFraction >= 1.0 )
                {
                
                }
                else
                {
                    CBaseEntity@ eGrab = g_EntityFuncs.Instance( tr.pHit );
                    
                    if(eGrab !is null)
                    {
                        
                        g_Game.AlertMessage( at_console, "Grabbing thing: " + eGrab.pev.classname + ", Friction: " + eGrab.pev.friction + "\n" );
                        
                        if(eGrab.pev.ClassNameIs("gsf_box") || eGrab.pev.ClassNameIs("gsf_3x2"))
                        {
                            Vector vecToEntity = (m_pPlayer.pev.origin - eGrab.pev.origin).Normalize();
                            eGrab.pev.velocity = vecToEntity * grabForce;
                            float distToEntity = (eGrab.pev.origin - m_pPlayer.pev.origin).Length();
                            
                            if(distToEntity <= grabToHoldDistance)
                            {
                                @eHeld = g_EntityFuncs.Instance( tr.pHit );
                                eHeld.pev.movetype = MOVETYPE_FLY;
                                self.m_flNextSecondaryAttack = g_Engine.time + 0.5;
                            }
                        }
                    }
                }
            
            }
        }

    Code:
        void WeaponIdle()
        {
            //Object moves with player
            if(eHeld !is null)
            {
                g_Game.AlertMessage( at_console, "Now holding: " + eHeld.pev.classname  + " \n" );
               
                Vector vecToEntity = ((m_pPlayer.pev.origin + (g_Engine.v_forward * holdDistance)) - eHeld.pev.origin).Normalize();
                float distToEntity = (eHeld.pev.origin - (m_pPlayer.pev.origin + (g_Engine.v_forward * holdDistance))).Length();
                
                if(distToEntity <= 5)
                {
                    eHeld.pev.basevelocity = eHeld.pev.basevelocity * 0;
                    eHeld.pev.velocity = eHeld.pev.velocity * 0;
                }
                else{ eHeld.pev.basevelocity = vecToEntity * grabForce * 1.11; }
                                        
                if(distToEntity >= dropDistance)
                {
                    g_Game.AlertMessage( at_console, "Now dropping: " + eHeld.pev.classname + "\n" );
                    eHeld.pev.movetype = MOVETYPE_TOSS;
                    @eHeld = null;
                }    
            }
        }

    The problems i have are in WeaponIdle() (holding entity).
    So i am giving the entity a velocity to a position in front of the player, but it always moves past this point and is moving circles around that point.
    If the player is moving too, that circles get bigger and bigger and the entity is moving with super high speed through the whole level.

    I have experimented with velocity/basevelocity, movetypes, more/less velocity, velocity multiplier dependent on distance to point, resetting velocity/basevelocity ...
    Really out of ideas here ...

  2. #2
    Registered User
    Join Date
    Feb 2016
    Location
    Germany
    Posts
    146

    Re: Buildsystem/"Gravitygun" problems

    I had an idea:

    Not setting velocity, but setting the entity origin. Then i would have to check if the entity is stuck in anything and eventually unstuck it.
    But for that i would need a custom hull for TraceHull, which is not possible right?

  3. #3
    Registered User
    Join Date
    Feb 2016
    Location
    Germany
    Posts
    146

    Re: Buildsystem/"Gravitygun" problems

    Okay i managed to check for collisions with a few TraceLines.
    It does not really feel like a Gravitygun now, but it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •