Results 1 to 6 of 6

Thread: Leaning detect

  1. #1
    Private First Class RobsoN's Avatar
    Join Date
    Jan 2013
    Location
    /home/cod2/
    Posts
    230
    Thanks
    119
    Thanked 95 Times in 64 Posts

    Leaning detect

    Hello everyone,

    Izno told me nice idea to detect leaning. Link origin to tag_eye and detect difference between origins.
    The problem is i haven't got idea how to do that (detect difference). I got only script for spawn and link:

    PHP Code:
    eye spawn("script_origin",self getEye());
        
    eye linkto(self"tag_eye"); 
    If you can, please help.
    Regards RobsoN.

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    PHP Code:
    dostuffonspawn()
    {
        if(
    isdefined(self.eye))
            
    self.eye delete();
        
    eye spawn("script_origin"self.origin);
        
    self.eye eye;
        
    eye thread deleteon("disconnect"self);
        
    wait 0.05//cant linkto() directly on spawn. Needs wait. waittillframeend; might do the job here too.
        
    if(!isdefined(Self)) //user might disconnect
            
    return;
        
    eye linkto(self"tag_eye");
    }

    isleaning()
    {
        if(!
    isdefined(self.eye))
            return 
    "no";
        
    right_2d anglestoright((0self getplayerangles()[1], 0));
        
    vec self.eye.origin self.origin;
        
    dot vectordot(vecright_2d);
        if(
    dot 5)
            return 
    "right";
        else if(
    dot < -5)
            return 
    "left";
        else
            return 
    "no";
    }

    deleteon(eventuser)
    {
        
    user waittill(event);
        if(
    isdefined(self))
            
    self delete();


  3. The Following User Says Thank You to IzNoGoD For This Useful Post:

    RobsoN (6th August 2013)

  4. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    The 5 and -5 are estimations. Might require proper tweaking.

  5. The Following User Says Thank You to IzNoGoD For This Useful Post:

    RobsoN (6th August 2013)

  6. #4
    Private First Class RobsoN's Avatar
    Join Date
    Jan 2013
    Location
    /home/cod2/
    Posts
    230
    Thanks
    119
    Thanked 95 Times in 64 Posts
    So pro. Thanks you very much IzNoGod. Now Im able to read more about vectors.

  7. #5
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Isn't this better?
    PHP Code:
    isleaning()
    {
        if(!
    isdefined(self.eye))
            return 
    0;
        
    right_2d anglestoright((0self getplayerangles()[1], 0));
        
    vec self.eye.origin self.origin;
        
    dot vectordot(vecright_2d);
        if(
    dot 5)
            return 
    1// right
        
    else if(dot < -5)
            return -
    1// left
        
    else
            return 
    0

    Now it returns -1 for left and 1 for right.

    Edit: a other way to do it is to use kung's extensions. It has a leanleft/right buttonpressed function.
    Last edited by Mitch; 6th August 2013 at 19:11.

  8. The Following User Says Thank You to Mitch For This Useful Post:

    RobsoN (6th August 2013)

  9. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Ofc it is, was just example code

Posting Permissions

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