Results 1 to 3 of 3

Thread: [advanced] movegravity() and movement vectors

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,573
    Thanks
    17
    Thanked 918 Times in 572 Posts

    [advanced] movegravity() and movement vectors

    First off, the docs on movegravity state the following:
    Code:
    MoveGravity( <initial velocity>, <time> )
     Module: Motion
    
    Summary:
    Fling this entity.
    
    
    
    Call this on: script_model, script_origin or script_brushmodel 
    
    
    
    Example:self MoveGravity( break_vector, time );
    
    
    Required Args:1 : <initial velocity> The initial velocity to fling this entity at
    2 : <time> The time to move the entity in seconds
    Closer inspection reveals the following:
    1. Movegravity() will fling an object into a certain direction
    2. Movegravity() will apply the correct rate of gravity to the object while doing so
    3. (experimentally found) movegravity() doesnt care for any obstacle. It will just keep moving until time runs out.

    4. Movegravity() needs both a time and a start vector.


    Now lets go experiment.


    The time part: movegravity() will move an object for as long as the time did not run out yet. So if you tell movegravity() to move an object for 10 seconds, the object will be moved for 10 seconds, regardless of obstacles of ANY kind.
    You can break this movement by changing/setting the origin of the object or by just applying another move function on it.

    The start vector part: This is where it gets interesting. movegravity() does sorta give the object an initial kick in a certain direction at a certain magnitude.

    Experimenting reveals that setting a (0,0,0) initial vector will make the object fall. Setting (0,0,1000) will give the object a ginormous kick upwards.

    Now the really fun part of all this. Using movegravity() to make objects "jump" from point A to point B.

    We can assume objects which are moved by movegravity() with a positive startvector move in a parabolic fashion. Therefore, we have 2 theoretical points when an object is at a certain height. First point is when the object is going up, second point is where the object is going down (unless ofcourse the desired height is at the top of the parabolic movement or below the start)
    As we are only interested in the point where the object is moving DOWN (realism and shit), calculations just became a lot easier.

    First off, familiarize yourself with the following formula:

    Code:
    s=0.5*a*t^2+v0*t
    where
    s=distance travelled
    a=acceleration
    t=time elapsed
    v0=initial speed

    You might remember this formula. If not, wikipedia it or just assume it is correct.

    Now the tricky part which most of you will not know yet: this formula applies to both scalars (normal numbers) and vectors.

    This means, that the symbols can also mean:

    s=vector of distance travelled (3d)
    a=acceleration in 3 dimensions
    t=time elapsed (no, nothing changed here)
    v0=initial speed in 3d

    As one can easily see here, the v0 resembles the required input for the movegravity() function.

    The a is a bit harder. This is the acceleration by the gravity in 3d. The gravitational vector looks like this:
    Code:
    (0,0,-g)
    where g is the gravitational acceleration (9.8m/s^2)
    As this acceleration is downward, it is negative on the z-axis.

    Now, calculating jump height of a normal player reveals the following:

    s=40 units (normal player jump height)
    a=(0,0,-800) (normal g_gravity in a server)
    v0 and t both unknown.

    Now we have 2 unknown vars and only 1 equation. This wont work. We need an additional equation.

    We know that the speed at the top of the jump is zero (dont know why? ask your science teacher-not me. Or wiki it.)

    v(t)=v0+a*t
    or (with v(t)=0)
    v0= -a*t on t=tTop
    If we solve this in 1-dimension, we can replace a with -800, so we can replace t with:
    t=v0/a

    Which leads us back to our first equation:
    s=0.5*a*t^2+v0*t
    replacing t with v0/a results in:
    s=0.5*a*(v0/a)^2+v0*(v0/a)
    or, setting both s and a to the found parameters:
    40=(0.5/-800)*v0^2+v0^2/800
    or
    40= ((-1/1600)+(1/800))*v0^2
    40= 1/1600*v0^2
    64000=v0^2
    Getting the square root of 64000 reveals v0 (at least in z-direction) for a normal jumping player to be approximately:
    250 units/second.

    The rest of the tutorial is still missing at this point. Will update/post to this thread to add more info

  2. The Following 5 Users Say Thank You to IzNoGoD For This Useful Post:

    Killer.Pro (27th October 2012),kung foo man (26th October 2012),Leal (26th November 2013),Ni3ls (17th March 2014),STAUFFi (26th October 2012)

  3. #2
    Private First Class voron00's Avatar
    Join Date
    Nov 2014
    Posts
    226
    Thanks
    62
    Thanked 190 Times in 101 Posts
    A 'reversed' movegravity function in case anyone wants to 'mess around with' in libcod:

    PHP Code:
    void gsc_entity_movegravity(scr_entref_t id)
    {
        
    vec3_t dir;
        
    float time;

        if ( ! 
    stackGetParams("vf", &dir, &time))
        {
            
    stackError("gsc_entity_movegravity() one or more arguments is undefined or has a wrong type");
            
    stackPushUndefined();
            return;
        }

        
    gentity_t *entity = &g_entities[id];

        
    entity->s.pos.trType TR_GRAVITY;
        
    entity->s.pos.trTime level.time;
        
    entity->s.pos.trDuration time 1000.0;

        
    VectorCopy(entity->r.currentOriginentity->s.pos.trBase);
        
    VectorCopy(direntity->s.pos.trDelta);

        
    BG_EvaluateTrajectory(&entity->s.poslevel.timeentity->r.currentOrigin);
        
    SV_LinkEntity(entity);

        
    stackPushBool(qtrue);

    sudo apt-get rekt

  4. The Following User Says Thank You to voron00 For This Useful Post:

    kung foo man (6th January 2019)

  5. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,573
    Thanks
    17
    Thanked 918 Times in 572 Posts
    Seems like that allows for lower gravity/higher gravity movegravity() functions as well.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

    Sending me a private message makes me want to help you LESS.

Posting Permissions

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