Obtaining the Surface Normal of a Touched Wall

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)

Obtaining the Surface Normal of a Touched Wall

Postby Pyhrrous » Sat Nov 20, 2021 9:01 pm

See title; this is for ZScript, just in case someone asks.

I'd like to find the surface normal of any wall that the player touches, from the side of the wall that they touched. I do understand that LineTrace exists, but I would like to know if there's a pre-existing way to get a normal vector before I try working with it.

Anyone have any pointers?
User avatar
Pyhrrous
 
Joined: 14 Jul 2020

Re: Obtaining the Surface Normal of a Touched Wall

Postby Apeirogon » Mon Nov 22, 2021 4:17 am

Unless I forgot how to count
Code: Select allExpand view
vector2 get_line_normal_to_player(vector3 player_pos, line test_line)
{
    //normal to the vector in 2d case is (vector.-y, vector.x), simple rotation on 90 degree
    //works only in 2d case
    if(player_pos.xy dot (test_line.delta.-y, test_line.delta.x) >= 0)
        return (test_line.delta.-y, test_line.delta.x);
    else return (test_line.delta.y, test_line.delta.-x);
}

https://github.com/coelckers/gzdoom/blo ... ta.zs#L167
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Obtaining the Surface Normal of a Touched Wall

Postby Pyhrrous » Mon Nov 22, 2021 2:02 pm

Apeirogon wrote:Unless I forgot how to count
Code: Select allExpand view
vector2 get_line_normal_to_player(vector3 player_pos, line test_line)
{
    //normal to the vector in 2d case is (vector.-y, vector.x), simple rotation on 90 degree
    //works only in 2d case
    if(player_pos.xy dot (test_line.delta.-y, test_line.delta.x) >= 0)
        return (test_line.delta.-y, test_line.delta.x);
    else return (test_line.delta.y, test_line.delta.-x);
}

https://github.com/coelckers/gzdoom/blo ... ta.zs#L167


When I added this to my file with some value tracing code on it and attempted to run, I got an "Unexpected '-'" error. Were the - symbols supposed to be before their respective "test_line"s?

Making that replacement and assuming that this is the intended output, this function doesn't seem to be what I'm looking for. It returns the delta of the line length rather than the normal.

I'll make my own jab at this code and get back here with the results, once I have them.

EDIT: Err... how would I go about getting the endpoints of a line? Planning on using the signed distance of the player's XY position in relation to the line, which is what I need this for.
User avatar
Pyhrrous
 
Joined: 14 Jul 2020

Re: Obtaining the Surface Normal of a Touched Wall

Postby Apeirogon » Mon Nov 22, 2021 2:56 pm

Replace all test_line.delta.-y and test_line.delta.-x to -test_line.delta.y and -test_line.delta.x.
User avatar
Apeirogon
I have a strange sense of humour
 
Joined: 12 Jun 2017

Re: Obtaining the Surface Normal of a Touched Wall

Postby Pyhrrous » Mon Nov 22, 2021 6:15 pm

Yeah, it's still not producing the desired effect. Running this function on two walls on opposite sides of a hallway does not produce opposite-signed return values.

Gonna re-ask this again, I suppose: how do I get the start and endpoints of a line found from LineTrace?
User avatar
Pyhrrous
 
Joined: 14 Jul 2020

Re: Obtaining the Surface Normal of a Touched Wall

Postby Pyhrrous » Tue Nov 23, 2021 9:52 am

Okay, I think I found a satisfactory way to do this. If anyone knows there's a more efficient method though, do let me know.

Spoiler:
User avatar
Pyhrrous
 
Joined: 14 Jul 2020


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest