GetShootPos() Only works when player moves?

I am trying to make a cursor for a 3D2D RoundedRect.



local panelPos = self:GetPos() + Vector(8,-26,82)
local trace = LocalPlayer():GetShootPos()
local doitnow = self:WorldToLocal(trace)

print(doitnow.x)

local d = panelPos:Dot(Vector(100,100,0))
	cam.Start3D2D(panelPos, Angle(0,90,90), 0.5)
		draw.RoundedBox(0, 0, 0, 100, 100, Color(255,0,255))
		draw.RoundedBox(0, doitnow.x,1,10, 10, Color(0,0,255))
	cam.End3D2D()



For some reason the cursor shows up fine and everything… BUT it will only move when I move with the WASD keys. When I move my screen, the cursor is totally unaffected by the aim movement.
Any ideas?
Thanks!

You don’t need to refrence localplayer for local eye traces and positions, use the global
EyePos, EyeAngles, and EyeVector functions.

For your actual problem it might have to do in how you’re actually calling this code.

Doing it all in ENT:Draw() in cl_init
Heres a vid:

The global functions EyePos and EyeAngles (I haven’t tested EyeVector) returns incorrect results in some cases (many of my bugs have been caused by this), do not use them.

What would be my best bet in this instance?

If it was a solid screen then I would say use tracers, but it this case… You gotta use player:GetAimVector() and do some vector magic.

It’s :GetAimVector().

Player:GetAimVector( )? Is that what Im best to use in this situation?

Im now using:



local trace = LocalPlayer():GetAimVector( )
local doitnow = self:WorldToLocal(trace)


I have the doitnow.x constantly printed to the console and the number hardly changes. Is this because I need to trace.x = trace.x*100 to make it more sensitive? This isnt very accurate…

:GetAimVector( ) Returns aim vector ( A line with length of 1 from your head ( ply:GetShootPos() ) basically, in the direction of your view ) and it obviously won’t magically make everything work.

I’ve had no problems with them in SinglePlayer or on a Dedi. Regardless:

[lua] – generic math functions
local function add_v3v3(a, b)
return Vector(a.x + b.x, a.y + b.y, a.z + b.z)
end

local function sub_v3v3(a, b)
return Vector(a.x - b.x, a.y - b.y, a.z - b.z)
end

local function dot_v3v3(a, b)
return a.x * b.x + a.y * b.y + a.z * b.z
end

local function mul_v3_fl(a, f)
a.x = a.x * f
a.y = a.y * f
a.z = a.z * f
return a
end

– intersection function
local function isect_line_plane_v3(p0, p1, p_co, p_no, epsilon)
epsilon = 0.000001
–[[
p0, p1: define the line
p_co, p_no: define the plane:
p_co is a point on the plane (plane coordinate).
p_no is a normal vector defining the plane direction; does not need to be normalized.

return a Vector or None (when the intersection can't be found).
http://stackoverflow.com/questions/5666222/3d-line-plane-intersection
--]]

local u = sub_v3v3(p1, p0)
local w = sub_v3v3(p0, p_co)
local dot = dot_v3v3(p_no, u)

if math.abs(dot) > epsilon then
	--[[
	the factor of the point between p0 -> p1 (0 - 1)
	if 'fac' is between (0 - 1) the point intersects with the segment.
	otherwise:
	 < 0.0: behind p0.
	 > 1.0: infront of p1.
	--]]
	local fac = -dot_v3v3(p_no, w) / dot
	u = mul_v3_fl(u, fac)
	return add_v3v3(p0, u)
else
	-- The segment is parallel to plane
	return nil
end

end[/lua]

I used this magic for vector plane intersection.

Why the hell do you define your own addition, subtraction and scalar multiplication for vectors?

[editline]3rd December 2013[/editline]

Also way to over complicate stuff.

[lua]local function intersectRayPlane( rayPos, rayDir, planePos, planeNormal )
local t = planeNormal:Dot( planePos - rayPos ) / planeNormal:Dot( rayDir )
return rayPos + rayDir * t
end[/lua]

I have no idea how to do anything more complicated than simple vector operations, I don’t do complicated vectors my head explodes, I just converted a function I found on the google, if you had read the code you would see the link in the code. Thanks anyway.

You should educate yourself on basic vector operations then (namely addition, substraction and scalar multiplication just like the ones you defined yourself).

Damn people. http://wiki.garrysmod.com/page/util/IntersectRayWithPlane

Nobody can remember every vauge function, especially when searching the wiki with things like “Intersect” comes up with no results because the search is a nazi.

Here’s for future reference:
Search it on Google using “site:wiki.garrysmod.com intersect”

WHAT!? There is such a function? Jesus christ.
Thanks guys!