Results 1 to 4 of 4

Thread: [AI movement] Jumping using movegravity()

  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    [AI movement] Jumping using movegravity()

    PHP Code:
    jump(startend)
    {
        
    height end[2] - start[2];
        
    v0 275;
        
    t0 v0 getcvarint("g_gravity");
        
    s0 0.5 getcvarint("g_gravity") * t0 t0;
        
    height -= s0;
        if(
    height 0)
            return 
    false//no jumping possible. Target too high.
        
    t1sq = -height getcvarint("g_gravity");
        
    time int((sqrt(t1sq) + t0) * 20) / 20;
        
    xdist end[0] - start[0];
        
    ydist end[1] - start[1];
        
    xspeed xdist time;
        
    yspeed ydist time;
        
    self movegravity((xspeedyspeedv0), time);
        
    wait time;
        
    self.origin end;
        return 
    true;

    Just some math...
    To change this function into fall(), just set v0 to 0, t0 to 0 or s0 to 0. (or remove all associated stuff)

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

    Jeplaa (18th May 2013),kung foo man (18th May 2013),Ni3ls (18th May 2013)

  3. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    Thats a nice function

    Though missing sqrt, so I post your intsqrt() and the 2 sqrt-function of the extension:

    PHP Code:
    sqrt(arg) { return closer(800arg); }
    invSqrt(arg) { return closer(801arg); } // check: http://www.beyond3d.com/content/articles/8/

    intsqrt(input)
    {
        
    output 0;
        while(
    output output input)
            
    output++;
        if(
    maps\mp\_utility::abs(input output output) > maps\mp\_utility::abs(input - (output 1) * (output 1)))
            
    output--;
        return 
    output;

    File is here: http://killtube.org/downloads/cod2/e...n/std/math.gsc
    timescale 0.01

  4. The Following User Says Thank You to kung foo man For This Useful Post:

    Ni3ls (18th May 2013)

  5. #3
    Private
    Join Date
    Jan 2013
    Location
    Hungary
    Posts
    113
    Thanks
    10
    Thanked 74 Times in 45 Posts
    I have also wrote a sqrt function, its accurate to 6 decimals:
    PHP Code:
    sqrt)
    {
        
    0;
        for ( 
    1<= 1000000*= 10 )
        {
            while ( 
    <= )
                
    += (i);

            if ( 
    )
                
    -= (i);
        }

        return 
    a;

    To increase the accuracy write a bigger number in 'for' cycle.

    And an other mathematical function:
    PHP Code:
    vectorCross(vec1vec2)
    {
        
    result =
        (
    vec1[1]*vec2[2] - vec2[1]*vec1[2]) -
        (
    vec1[0]*vec2[2] - vec2[0]*vec1[2]) +
        (
    vec1[0]*vec2[1] - vec2[0]*vec1[1]);

        return 
    result;


  6. The Following 2 Users Say Thank You to randall For This Useful Post:

    kung foo man (18th May 2013),Ni3ls (18th May 2013)

  7. #4
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    Quote Originally Posted by randall View Post
    I have also wrote a sqrt function...
    my one:
    PHP Code:
    sqrt)
    {
        
    x;

        for( 
    *0.25 abs) >= 0.001 = ( + ( ) ) * 0.5 )
        {
            
    y;
        }

        return 
    y;


  8. The Following 3 Users Say Thank You to serthy For This Useful Post:

    kung foo man (19th May 2013),Ni3ls (19th May 2013),randall (20th May 2013)

Posting Permissions

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