Results 1 to 3 of 3

Thread: [advanced] movegravity() and movement vectors

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Thanked 931 Times in 580 Posts

    [advanced] movegravity() and movement vectors

    First off, the docs on movegravity state the following:
    MoveGravity( <initial velocity>, <time> )
     Module: Motion
    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:

    s=distance travelled
    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:
    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.)

    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:

    Which leads us back to our first equation:
    replacing t with v0/a results in:
    or, setting both s and a to the found parameters:
    40= ((-1/1600)+(1/800))*v0^2
    40= 1/1600*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 (25th November 2013),Ni3ls (17th March 2014),STAUFFi (26th October 2012)

  3. #2
    Private First Class voron00's Avatar
    Join Date
    Nov 2014
    Thanked 198 Times in 106 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");

    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;




    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
    Thanked 931 Times in 580 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