Wire: E:nearestPoint(V) returns different vectors depending on whether or not the entity is "solid"

Created on 31 Jul 2016  路  9Comments  路  Source: wiremod/wire

I made an automated door using E:nearestPoint(owner():pos()) and E:propNotSolid(1/0) that will open if the distance between the player and the nearest point of the prop to the player is less than a certain value. E:nearestPoint(V) returns different vectors for the prop depending on whether or not it's solid or not.
This E2 can demonstrate:

@name 
@outputs NearestPoint:vector
@persist E:entity
if(first()){
    E = propSpawn("models/hunter/plates/plate1x2.mdl",entity():pos() + vec(0,0,48),ang(0,0,90),1)
    holoCreate(1)
    runOnTick(1)
}

holoPos(1,E:nearestPoint(owner():pos()))
NearestPoint = E:nearestPoint(owner():pos())

if(E:nearestPoint(owner():pos()):distance(owner():pos()) < 50){
    E:propNotSolid(1)
}
else{
    E:propNotSolid(0)
}

The hologram shows E:nearestPoint(owner():pos()). If you walk to the side of the prop, you can see how the prop flickers between solid (closed) and non-solid (open).

Can't fix E2 Garry's fault

Most helpful comment

it's a tag we should have had years ago

All 9 comments

can you make screenshots to illustrate it for the people who are too lazy to open gmod? :)

Either way, the implementation is just this:NearestPoint(...), so you'll have to take it up with Garry :)
See also: https://wiki.garrysmod.com/page/Entity/NearestPoint

Check if the bounding box changes too.
That seems to be the base of that calculation

Like TomyLobo already said, this function was made by garry (or possibly it's inside the source engine?) so there's nothing we can do.

"Garry's fault" is a new tag now? Haha.

it's a tag we should have had years ago

I found that nearestPoint returns the position of the prop as if it were at ang(0,0,0). I added another hologram in my E2 that can demonstrate that.

@outputs NearestPoint:vector
@persist E:entity
if(first()){
    E = propSpawn("models/hunter/plates/plate1x2.mdl",entity():pos() + vec(0,0,48),ang(0,0,90),1)
    holoCreate(1)
    holoCreate(2)
    holoModel(2,"models/hunter/plates/plate1x2.mdl")
    holoPos(2,E:pos())
    runOnTick(1)
}

holoPos(1,E:nearestPoint(owner():pos()))
NearestPoint = E:nearestPoint(owner():pos())

if(E:nearestPoint(owner():pos()):distance(owner():pos()) < 50){
    E:propNotSolid(1)
}
else{
    E:propNotSolid(0)
}

@Shadotak tested your E2, the white holograms follows me wherever I go and no matter how I rotate the prop. Seems to work as intended.

EDIT: gonna test when it's constantly propNotSolid'd
EDIT 2: alright it looks like you are correct. But again, this is garry's fault.

Here, I added a custom user defined function to your E2 and it seems to work.

@outputs NearestPoint:vector
@persist E:entity
if(first()){
    E = propSpawn("models/hunter/plates/plate1x2.mdl",entity():pos() + vec(0,0,48),ang(0,0,90),1)
    holoCreate(1)
    runOnTick(1)

    E:propNotSolid(1)

    #weld
    #this allows us to move the prop around by physgunning the E2
    #(just hit R with physgun to unfreeze when ready)
    #you may need to enable constraint core to gain access to this function
    #if your server doesn't have it already
    weld(E,entity()) 

    holoCreate(2)
    holoColor(2,vec(255,0,0))

    function vector entity:newNearestPoint(Pos:vector) {
        local LocalPos = This:toLocal(Pos)
        local MinCorner = This:aabbMin()
        local MaxCorner = This:aabbMax()
        local ClampedPos = clamp(LocalPos,MinCorner,MaxCorner)
        return This:toWorld(ClampedPos)
    }
}

NearestPoint = E:nearestPoint(owner():pos())
holoPos(1,NearestPoint)

NearestPoint2 = E:newNearestPoint(owner():pos())
holoPos(2,NearestPoint2)

I'm not sure if it's a good idea to replace the official nearestPoint function with this, since garry's one might handle certain use cases that mine doesn't. It seems to work fine for your use case, though.

Oh thanks for the workaround. This works perfectly for what I was using the function for, since my doors will always be blocks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anticept picture Anticept  路  5Comments

CaptainPRICE picture CaptainPRICE  路  6Comments

CaptainPRICE picture CaptainPRICE  路  9Comments

TAbdiukov picture TAbdiukov  路  5Comments

CaptainPRICE picture CaptainPRICE  路  4Comments