PLAYER.SetEyeAngles() to an object angles?

Another problem: I need to snap players EyeAngles that it would only to an entity from lets say its back, for this example I’ve chosen a vehicle:


lua_run_cl LocalPlayer():SetEyeAngles(LocalPlayer():GetVehicle():GetAngles()+ Angle(0,90,0))

It should point to the vehicles back side, but the angle is not constant relative to the vehicle, how would I snap players angles to face an object from its perspective, while the object can be at any angle?

This snippet of code might have what you want.

local vehAng = ply:GetVehicle():GetAngles()
vehAng:RotateAroundAxis(ply:GetVehicle():GetUp(), 90)
ply:SetEyeAngles(vehAng)

Alright, tried your suggestion:


ply:SetEyeAngles(Veh:GetAngles():RotateAroundAxis(Veh:GetUp(), 90))

Still the angle is acting about the same way as before, not constant to the vehicle.

[lua]local a = v:GetAngles()
local p,y,r = a.p,a.y,a.r

pl:SetEyeAngles(Angle(90-p,y,r))[/lua]

I think you meant a.p, a.y, a.r.

Anyway: I feel really stupid now for not trying this in the first place, simply setting it like this:


ply:SetEyeAngles(Angle(0,90,0))

Sets the angle relative to the vehicle.

[editline]11th February 2011[/editline]

Thanks for trying to help tho.

What you’re thinking there shouldn’t work. You’re setting the player’s angle to a constant which won’t change with the angle of the vehicle.

I know, its weird, didn’t even try to see if this would work, cause I was sure it wouldn’t, before creating this thread, but it works, so I can’t complain.

It kinda makes sense though since the player is pretty much parented to the vehicle while driving.

Ah yeah, didn’t think of it that way.