Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Get angle of wall

  1. #1
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts

    Get angle of wall

    Hey there
    I'm currently trying to recreate my portal mod. Everything is working fine so far, but i have a small problem.
    I'm trying to spawn my portal model at a wall or at the floor/ceiling and thats working, but its not the right angle.
    I need a small function that gets the angle of whatever you are looking at (wall, floor, ceiling) but i absolutly dont know how.
    I think that should be possible if i try to get 3 points of what i'm looking at but thats all i have for now.
    Does there any function exist that someone has created in the past that i could use or anything else that i could use to get started?

    Sorry for my bad english, i hope its not to hard to understand.

  2. #2
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    PHP Code:
    trace bulletTrace(model.originmodel.origin + (somexdirsomeydirsomezdir), falsemodel);
    model.origin trace["position"];
    model.angles vectorNormalize(trace["normal"]) 
    Could be something like this or at least that is the direction you have to look for. The trace["normal"] is the thing you are looking for but not sure if it can be applied to models, this needs some testing but im 1 lazy ass...
    Edit: Also take a look at kung's portal mod https://killtube.org/showthread.php?...oD2-Portal-Mod proably has what you need.
    Last edited by voron00; 25th October 2016 at 10:52.
    sudo apt-get rekt

  3. #3
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Just put that trace["normal"] into your playfx function, or use vectortoangles() on it and set your model.angles to that.

    Might have to offset that a bit (90 degrees maybe)
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  4. #4
    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
    Uploaded my old portal mod: https://github.com/kungfooman/cod2_portal/

    Video:



    https://github.com/kungfooman/cod2_p...portal.gsc#L47
    Code:
    bluePortal.angles = utils\math::orientToNormal(newPos["normal"]+(0.01,0.01,0.01));
    Can't really remember why I added the 0.01, probably because wall vectors are mostly like 0,0,1 or 0,1,0 etc. and orientToNormal() didn't work with zero values.

    Edit: Server is testable here: /connect root.killtube.org:29900

    Server will run till root is restarted (aka screen session killed).
    Last edited by kung foo man; 26th October 2016 at 06:06. Reason: Add connect info
    timescale 0.01

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

    kubislav23 (30th October 2016)

  6. #5
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts
    Quote Originally Posted by kung foo man View Post
    Code:
    bluePortal.angles = utils\math::orientToNormal(newPos["normal"]+(0.01,0.01,0.01));
    I already tested that but for some reason its rotating my model into all directions.
    https://www.youtube.com/watch?v=hhnywxTmrlY

    The models at the spawn wall are in their normal direction if you spawn them with the radiant, just for comparison.

  7. #6
    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
    Would be useful if you post video with debug printbolds of normal + calculated angle.

    And show your exact code with your orientToNormal function.

    And try what IzNoGoD said: portal.angles = vectorToAngles(trace["normal"]);

    And add more surfaces to your map, which aren't all straight walls. Lots of different slopes to test all kinds of trace normals (or just test in a stock map, should have more variety in surfaces).
    timescale 0.01

  8. #7
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Which COD is that in your video Trance?

  9. #8
    Private
    Join Date
    Oct 2013
    Posts
    48
    Thanks
    10
    Thanked 4 Times in 2 Posts
    Quote Originally Posted by kung foo man View Post
    Would be useful if you post video with debug printbolds of normal + calculated angle.

    And show your exact code with your orientToNormal function.

    And try what IzNoGoD said: portal.angles = vectorToAngles(trace["normal"]);

    And add more surfaces to your map, which aren't all straight walls. Lots of different slopes to test all kinds of trace normals (or just test in a stock map, should have more variety in surfaces).
    The code behind the portal is this:
    Spoiler:

    Code:
    function watchAttack()
    {
        player = self;
        orangePortal = util::spawn_model("portal_orange", (0,0,-1000000), 0);
    
        i = 1;
    
        while(isDefined(player))
        {
            if(player AttackButtonPressed() && !player ThrowButtonPressed())
            {
                newPos = player _utils::lookAt(orangePortal);
    
                if(!isDefined(newPos))
                {
                    WAIT_SERVER_FRAME;
                    continue;
                }
    
                orangePortal.origin = newPos["position"];
                orangePortal.angles = VectortoAngles(newPos["normal"]) + (0,90,0);
                orangePortal.lookupNormal = newPos["normal"];
                orangePortal MoveZ(2,0.1);
    
                player IPrintLn(" ");
                player IPrintLn(" ");
                player IPrintLn(" ");
                player IPrintLn(i + ". GetPlayerAngles: " + player GetPlayerAngles());
                player IPrintLn(i + ". Normal: " + newPos["normal"]);
                player IPrintLn(i + ". orientToNormal: " + _utils::orientToNormal(newPos["normal"]+(0.01,0.01,0.01)));
                player IPrintLn(i + ". VectorToAngles: " + VectortoAngles(newPos["normal"]));
                i += 1;
    
                if(!isDefined(player.orangePortal))
                    player.orangePortal = orangePortal;
    
                while (self AttackButtonPressed())
                	WAIT_SERVER_FRAME;
            }
    
            WAIT_SERVER_FRAME;
        }
    
        orangePortal Delete();
    }


    orientToNormal:
    Spoiler:

    Code:
    function orientToNormal(normal)
    {
    	horNormal = (normal[0], normal[1], 0);
    	horLength = Length(horNormal);
    
    	if(!horLength)
    		return(0,0,0);
    
    	horDir = VectorNormalize(horNormal);
    	negHeight = normal[2] + -1;
    	tangent = (horDir[0] * negHeight, horDir[1] * negHeight, horLength);
    	plantAngle = VectortoAngles(tangent);
    
    	return plantAngle;
    }


    lookAt:
    Spoiler:

    Code:
    function lookAt(toIgnore)
    {
    	player = self;
    
    	originStart = player GetEye() + (0,0,25);
    	angles = player GetPlayerAngles();
    	forward = AnglesToForward(angles);
    
    	originEnd = originStart + VectorScale(forward, 1000000);
    
    	trace = BulletTrace(originStart, originEnd, false, toIgnore);
    
    	if (trace["fraction"] == 1)
    		return undefined;
    
    	return trace;
    }


    Its basically the same as in your portal mod. Its the stuff you have send me while i was trying to create the mod for cod4 years ago.
    The only difference i have found is that vectorScale is a build in function now, but i tested it with your vectorScale function too, no differences.

    I added more walls to my testmap so that there are more different angles to test on, i also added a few prints. If you need any other prints, let me know.

    New Video:
    https://www.youtube.com/watch?v=SunWQUnDbyU

    In the video i'm using
    Code:
    orangePortal.angles = VectortoAngles(newPos["normal"]) + (0,90,0);
    For now its the closest i can get to what i want.
    As you can see, its perfect for walls in any angle, but as soon as it gets to the ground or some kind of a ramp, its not working anymore.
    And for some reason the portal is sometimes stuck inside of the walls (starting at 9sec. in the video).


    Quote Originally Posted by Ni3ls View Post
    Which COD is that in your video Trance?
    Its Black Ops 3.
    Last edited by DjTranceFire; 27th October 2016 at 12:43.

  10. The Following User Says Thank You to DjTranceFire For This Useful Post:

    Ni3ls (27th October 2016)

  11. #9
    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
    PHP Code:
    function orientToNormal(normal)
    {
        
    horNormal = (normal[0], normal[1], 0);
        
    horLength Length(horNormal);

        if(!
    horLength)
            return(
    0,0,0);

        
    horDir VectorNormalize(horNormal);
        
    negHeight normal[2] + -1// <<<<<<<<<<<<<<<<<<<
        
    tangent = (horDir[0] * negHeighthorDir[1] * negHeighthorLength);
        
    plantAngle VectortoAngles(tangent);

        return 
    plantAngle;

    yiz m8 thats not how negation works: * -1 instead
    timescale 0.01

  12. #10
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Just vectorscale by -1.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

Posting Permissions

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