Jump to content

LinePick


Rick
 Share

Recommended Posts

LinePick(Vec3 start, Vec3 end, radius, collision type)

 

Example usage (modified from what's in the ActionSnake game):

function GetGroundHeight(ent)
local v = ent:GetPosition(1)
local v1 = Vec3(v.x, v.y + 10, v.z)
local v2 = Vec3(v.x, v.y - 10, v.z)
local Pick = LinePick(v1, v2, 0, 5)
local groundheight = ent.position.y

local CollisionEntityName =""
if Pick ~= nil then
	CollisionEntityName = Pick.entity:GetKey( "class")
	if CollisionEntityName == "Terrain" then
		groundheight = Pick.position.y
	end
end

return groundheight
end

 

Note: I'm not sure about the 5 for collision type. It works for what I'm using it for though. For most things it seems the BlitzMax usage is what is used for the Lua implementation.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

It does if you use the correct collision mask. 5 worked in my case, but it might also cause it to collide with other things. Mess around w/ the value and see if you can find one that works for you. I don't know if the collision is a bitwise mask and 5 is actually taking into account 4 and 1 (whatever they are) or if it means something else. I should probably read up on it more.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

from wiki

If collisionType is 0 all pickable entities will affect the ray test

 

I guess a terrain isn't a pickable entity? I need it to collide with anything and everything. My understanding is that this value is the value we assign with EntityType(). If that's the case then it seems I'd have to use the callback method to assign all my collision types?

 

5 didn't work for me either. The terrain must get an EntityType() value. Can that be changed?

Link to comment
Share on other sites

the terrain is a pickable entity, you just have to filter the results of the pick correctly because not everything you can do to or evaluate with a picked model/mesh can work on a terrain...

 

if pick~=nil then
if pick.entity:GetClass()==ENTITY_TERRAIN then
	terrain_posX=pick.position.x
else
	name = GetEntityKey(GetMeshModel(pick.entity),"name")
end
end

 

look at the scripts/constants/engine_const.lua for entity class values

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I'm confused at your code. All I'm after for the pick is the pick.position x, y, & z values. For the terrain it doesn't seem to return these values to me. I don't need to know what is between the 2 pivots because I don't much care what it is, I just need to know the point of intersection.

 

[EDIT]

As I look at it more, I put other models in the way and it doesn't do what I'm after so I'll have a second look at it when I get home.

Link to comment
Share on other sites

I'm confused at your code. All I'm after for the pick is the pick.position x, y, & z values. For the terrain it doesn't seem to return these values to me. I don't need to know what is between the 2 pivots because I don't much care what it is, I just need to know the point of intersection.

 

[EDIT]

As I look at it more, I put other models in the way and it doesn't do what I'm after so I'll have a second look at it when I get home.

 

ok... of course the above code wouldn't return anything for position if the entity class wasn't equal to a terrain... if all you are wanting is a position for your pick no matter what the entity class is:

pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,1000.0),0,0)
if pick~=nil then
pick_posX=pick.position.x
pick_posY=pick.position.y
pick_posZ=pick.position.z
end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Yeah, I use LinePick extensively in Weaponwerks, for obvious reasons.

 

You simple create assign a variable to the return value of LinePick, it will be a table with the following values:

local pick = LinePick(...)

 

pick.entity (TEntity)

pick.surface (TSurface)

pick.position (vec3)

pick.normal (vec3)

pick.triangle (number)

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

if pick.entity:GetClass()==ENTITY_TERRAIN then

 

 

Doesn't work for me. As it seems now the picking doesn't seem to work for me for the terrain. Any thoughts?

 

what does your pick command look like? because that code works for me... well at least it did the other day before the update...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

This works if the barrel gets in the way between the playerPivot and cameraPivot.

 

if EntityVisible(object.playerPivot, object.cameraPivot) == 0 then
				local p = LinePick(EntityPosition(object.playerPivot, 1), EntityPosition(object.cameraPivot, 1), 0, 0)
				if p ~= nil then
					if p.entity:GetClass()==ENTITY_TERRAIN then
						Notify("Terrain")
					end

					PositionEntity(object.cameraPivot, Vec3(p.position.x, p.position.y, p.position.z), 1)
					PointEntity(object.cameraPivot, object.playerPivot, 3, 1, 0)
					MoveEntity(object.cameraPivot, Vec3(0, 0, 1))
				end
			end

Link to comment
Share on other sites

This works if the barrel gets in the way between the playerPivot and cameraPivot.

 

if EntityVisible(object.playerPivot, object.cameraPivot) == 0 then
				local p = LinePick(EntityPosition(object.playerPivot, 1), EntityPosition(object.cameraPivot, 1), 0, 0)
				if p ~= nil then
					if p.entity:GetClass()==ENTITY_TERRAIN then
						Notify("Terrain")
					end

					PositionEntity(object.cameraPivot, Vec3(p.position.x, p.position.y, p.position.z), 1)
					PointEntity(object.cameraPivot, object.playerPivot, 3, 1, 0)
					MoveEntity(object.cameraPivot, Vec3(0, 0, 1))
				end
			end

 

 

im confused... its working now? whats the difference between that and what i showed? cuz it looks to be fundamentally the same...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Exactly, which is why I'm confused. I have a terrain and made a little mound. I place my character on it and a barrel next to him. The camera is a 3rd person view where I can rotate around my character. When I rotate it down where the terrain covers the player up nothing happens. When I rotate it so the barrel covers the player the camera moves where it should in front of the barrel. The whole idea is that if anything comes between the player and the camera, the camera would move to a spot where it can always see the player. This works for objects, just not the terrain.

Link to comment
Share on other sites

Well the thing is above it never hit the notify. So I did this:

 

local p = LinePick(EntityPosition(object.playerPivot, 1), EntityPosition(object.cameraPivot, 1), 0, 0)
				if p ~= nil then
					Notify(p.entity:GetClass())
                                       end

 

This returns 1 for the barrel and it never hits the Notify() at all for the terrain. So LinePick is return a nil for picking the terrain. Do I need to do something with the terrain? It's not painted or anything.

Link to comment
Share on other sites

Well the thing is above it never hit the notify. So I did this:

 

local p = LinePick(EntityPosition(object.playerPivot, 1), EntityPosition(object.cameraPivot, 1), 0, 0)
				if p ~= nil then
					Notify(p.entity:GetClass())
                                       end

 

This returns 1 for the barrel and it never hits the Notify() at all for the terrain. So LinePick is return a nil for picking the terrain. Do I need to do something with the terrain? It's not painted or anything.

 

no its doesn't need to be painted... maybe its the type of pick itself? try this code that uses the CameraPick:

require("Scripts/constants/collision_const")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")
require("scripts/classes/bullet")

--Variables
dx=0.0
dy=0.0
camerapitch=0.0
camerayaw=0.0
move=0.0
strafe=0.0

--Create a player controller
controller=CreateController(1.8,0.45,0.25,45)
controller:SetCollisionType(COLLISION_CHARACTER,0)
controller:SetPositionf(0,2,0,0)
controller:SetMass(10)

controller:SetPosition(fw.main.camera.position)
camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y
controller:Move(Vec3(0,-0.9,0))

local gunscale=0.6
local vwep = LoadMesh("abstract::vwep_hands.gmf")
LoadMesh("abstract::vwep_gun.gmf",vwep)
vwep:SetParent(fw.main.camera,0)
vwep:SetPosition(Vec3(-0.18*gunscale,-0.03*gunscale,0.37*gunscale),0)
vwep:SetScale(Vec3(0.04*gunscale,0.04*gunscale,0.04*gunscale))
local gundisplayposition = vwep:GetPosition()
sound_gunshot = LoadSound("abstract::gunshot.ogg")
source_gunshot = CreateSource(sound_gunshot)
source_gunshot:SetVolume(0.5)
vwep :SetShadowMode(0,1)
local displayposition=Vec3(-0.26/2.0,-0.03,0.19)
local muzzleflash = CreatePointLight(3)
muzzleflash:SetParent( vwep )
muzzleflash:SetColor(Vec4(1,0.6,0.0,1.0))
muzzleflash:SetPosition( displayposition )
muzzleflash:SetShadowMode(0)

HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
FlushKeys()
FlushMouse()

local pick
local camera = fw.main.camera
local remainingtime
local starttime=AppTime()
local gameduration=2--length of game in minutes
local gamemode=0

gunpos = vwep.position:Copy()

local smoothedgunswayamplitude=0.0
local smoothedgunswayspeed	=0.0
local guntime = 0.0
local recoil = 0.0
local lastfiretime=0.0
local smoothrecoil=0.0
local swaydamping=0.0
local smoothswaydamping=0.0
local lightsmoothing =0.0
local gunlight = 0.0

--Flashlight
flashlight = {}
flashlight.light = CreateSpotLight(8)
flashlight.light:Hide()
flashlight.sound_switch = LoadSound("abstract::switch.wav")
flashlight.state=0
flashlight.light:SetConeAngles(30,35)
flashlight.light:SetRotation(Vec3(5,0,0))
flashlight.light:SetShadowmapSize(512)
flashlight.light:Paint(LoadMaterial("abstract::flashlight.mat"))

function flashlight:SetState( state )
if state~=self.state then
	self.state=state
	if state==0 then
		self.light:Hide()
	else
		self.light:Show()
	end
	if self.sound_switch~=nil then
		self.sound_switch:Play()
	end
end
end


function ShootBullet( position, direction )
--	local speed=100.0
--	local pick = LinePick( position, Vec3(position.x+direction.x * speed) )	
end


--main function
while KeyHit(KEY_ESCAPE)==0 do
jump=KeyHit(KEY_SPACE)*6.0
if controller:IsAirborne()==1 then jump=0 end


local time = AppTime()/3200.0
local frame = time*(179.0-96.0)+96.0
frame=clamp( frame, 96, 179 )
vwep:Animate(96,1,0,1)


--Camera look
gx=round(GraphicsWidth()/2)
gy=round(GraphicsHeight()/2)
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())
MoveMouse(gx,gy)
camerapitch=camerapitch+dy
camerayaw=camerayaw-dx
camerapitch=math.min(camerapitch,90)
camerapitch=math.max(camerapitch,-90)
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

movespeed=6
movesmoothing=10
if controller:IsAirborne()==1 then
	movesmoothing=200
end

--Player movement
move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)
strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)

pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,1000.0),0,0)

if pick~=nil then
	pick_posX=pick.position.x
	pick_posY=pick.position.y
	pick_posZ=pick.position.z
	pvalue = pick.entity:GetClass()
end


--Use objects
if KeyHit(KEY_E)==1 then

	if pick~=nil then
		repeat
			if pick.entity:GetClass()==ENTITY_MODEL then
				break
			end
			pick.entity=pick.entity.parent
		until pick.entity==nil
		if pick.entity~=nil then
			pick.entity:SendMessage("use",controller,0)
		end
	end
end

--Update controller
controller:Update(camerayaw,move,strafe,jump,40,10)

fw:Update()

if KeyHit(KEY_F)==1 then
	flashlight:SetState(1-flashlight.state)
end

--Position camera
camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)

time=AppTime()
gunfirefrequency=80
gunswayspeed=0.001*20.0
gunoffset = gunpos:Copy()
gunswayamplitude = 0.02
if KeyDown(KEY_W)==1 or KeyDown(KEY_D)==1 or KeyDown(KEY_A)==1 or KeyDown(KEY_S)==1 then
	gunswayamplitude = 0.03
	gunswayspeed=0.005*20.0
end
smoothedgunswayamplitude = Curve( gunswayamplitude, smoothedgunswayamplitude,8.0  ) 
smoothedgunswayspeed = Curve( gunswayspeed, smoothedgunswayspeed,8.0 ) 
if smoothrecoil<0.001 then
	guntime = guntime + AppSpeed() * smoothedgunswayspeed * math.max(0.0,1.0 - smoothswaydamping)
end
gunoffset.z = gunoffset.z - smoothrecoil * 0.05
--smoothedgunswayamplitude = smoothedgunswayamplitude * (1.0 - smoothswaydamping)
gunoffset.x = gunoffset.x + math.sin( guntime ) * smoothedgunswayamplitude * gunscale
gunoffset.y = gunoffset.y + (1.0-math.cos( guntime*2.0 )) * 0.005 * gunscale-- * math.min(1.0,1.0 - smoothswaydamping))
vwep:SetPosition( gunoffset )
recoil = recoil-0.1
swaydamping = math.max( swaydamping - 0.05, 0.0 )
recoil = math.max(recoil,0.0)
smoothrecoil=Curve(recoil,smoothrecoil,3.0)
smoothswaydamping = inc( swaydamping ,smoothswaydamping,0.01 )
gunlight = math.max( gunlight- 0.2, 0.0 )
lightsmoothing =gunlight-- Curve(gunlight,lightsmoothing,8.0) 
muzzleflash:SetColor(Vec4(1.0*lightsmoothing,0.6*lightsmoothing,0.0,1.0))
if lightsmoothing <0.01 then
	muzzleflash:Hide()
end
if MouseDown(1)==1 then
	if AppTime()-lastfiretime>gunfirefrequency then
		recoil = 1.0
		lastfiretime=AppTime()+math.random(0,20)
		gunswayspeed=0.0
		gunlight = 1.0
		source_gunshot:Play()
		source_gunshot:SetPitch(1.0 + (math.random()-0.5)*0.05 )
		swaydamping = 1.0
		muzzleflash:Show()

		CreateBullet(vwep:GetPosition(1) , fw.main.camera.mat:K():Scale(300))

	end
end

UpdateBullets()

flashlight.light:SetPosition(fw.main.camera:GetPosition(1))
flashlight.light:SetRotationf( curveangle( fw.main.camera.rotation.x, flashlight.light.rotation.x, 3.0/AppSpeed() ), curveangle( fw.main.camera.rotation.y, flashlight.light.rotation.y, 3.0/AppSpeed() ) )
flashlight.light:Movef(-0.07,-0.04,0.02)

fw:Render()
DrawText(pick_posX,0,100)
DrawText(pick_posY,0,120)
DrawText(pick_posZ,0,140)
DrawText(pvalue,0,160)
Flip(0)

end

controller:Free()
vwep:Free()

ShowMouse()

 

this works for me... shows the terrain when its picked and a model

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Oh so your using CameraPick to pick the terrain and not LinePick to see if the terrain comes between 2 points. I assume that's different. This did work in older versions of LE because I'm copying the code I used in a C++ program I made.

 

 

So can anyone verify that the terrain is considered in LinePick?

Link to comment
Share on other sites

Oh so your using CameraPick to pick the terrain and not LinePick to see if the terrain comes between 2 points. I assume that's different. This did work in older versions of LE because I'm copying the code I used in a C++ program I made.

 

 

So can anyone verify that the terrain is considered in LinePick?

 

yes terrain is considered with a linepick... so that just leaves your positioning of the camera thats causing the issue

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I just don't think it is (it should). The barrel works just fine. I set the position of the camera to the cameraPivot location. The cameraPivot location is parented to the playerPivot. When I rotate the playerPivot with the mouse the cameraPivot follows, which means the camera follows. I would agree with you if the barrel didn't cause a collision with the ray from playerPivot to cameraPivot but it does.

Link to comment
Share on other sites

well it returns the correct values for me whenever i use linepick...

require("Scripts/constants/collision_const")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")
require("scripts/classes/bullet")

--Variables
dx=0.0
dy=0.0
camerapitch=0.0
camerayaw=0.0
move=0.0
strafe=0.0

--Create a player controller
controller=CreateController(1.8,0.45,0.25,45)
controller:SetCollisionType(COLLISION_CHARACTER,0)
controller:SetPositionf(0,2,0,0)
controller:SetMass(10)

controller:SetPosition(fw.main.camera.position)
camerapitch=fw.main.camera.rotation.x
camerayaw=fw.main.camera.rotation.y
controller:Move(Vec3(0,-0.9,0))

local gunscale=0.6
local vwep = LoadMesh("abstract::vwep_hands.gmf")
LoadMesh("abstract::vwep_gun.gmf",vwep)
vwep:SetParent(fw.main.camera,0)
vwep:SetPosition(Vec3(-0.18*gunscale,-0.03*gunscale,0.37*gunscale),0)
vwep:SetScale(Vec3(0.04*gunscale,0.04*gunscale,0.04*gunscale))
local gundisplayposition = vwep:GetPosition()
sound_gunshot = LoadSound("abstract::gunshot.ogg")
source_gunshot = CreateSource(sound_gunshot)
source_gunshot:SetVolume(0.5)
vwep :SetShadowMode(0,1)
local displayposition=Vec3(-0.26/2.0,-0.03,0.19)
local muzzleflash = CreatePointLight(3)
muzzleflash:SetParent( vwep )
muzzleflash:SetColor(Vec4(1,0.6,0.0,1.0))
muzzleflash:SetPosition( displayposition )
muzzleflash:SetShadowMode(0)

HideMouse()
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
FlushKeys()
FlushMouse()

local pick
local camera = fw.main.camera
local remainingtime
local starttime=AppTime()
local gameduration=2--length of game in minutes
local gamemode=0

gunpos = vwep.position:Copy()

local smoothedgunswayamplitude=0.0
local smoothedgunswayspeed	=0.0
local guntime = 0.0
local recoil = 0.0
local lastfiretime=0.0
local smoothrecoil=0.0
local swaydamping=0.0
local smoothswaydamping=0.0
local lightsmoothing =0.0
local gunlight = 0.0

--Flashlight
flashlight = {}
flashlight.light = CreateSpotLight(8)
flashlight.light:Hide()
flashlight.sound_switch = LoadSound("abstract::switch.wav")
flashlight.state=0
flashlight.light:SetConeAngles(30,35)
flashlight.light:SetRotation(Vec3(5,0,0))
flashlight.light:SetShadowmapSize(512)
flashlight.light:Paint(LoadMaterial("abstract::flashlight.mat"))

function flashlight:SetState( state )
if state~=self.state then
	self.state=state
	if state==0 then
		self.light:Hide()
	else
		self.light:Show()
	end
	if self.sound_switch~=nil then
		self.sound_switch:Play()
	end
end
end


function ShootBullet( position, direction )
--	local speed=100.0
--	local pick = LinePick( position, Vec3(position.x+direction.x * speed) )	
end

cube = CreateCube()
MoveEntity(cube,Vec3(0,1,0))
--main function
while KeyHit(KEY_ESCAPE)==0 do
jump=KeyHit(KEY_SPACE)*6.0
if controller:IsAirborne()==1 then jump=0 end


local time = AppTime()/3200.0
local frame = time*(179.0-96.0)+96.0
frame=clamp( frame, 96, 179 )
vwep:Animate(96,1,0,1)


--Camera look
gx=round(GraphicsWidth()/2)
gy=round(GraphicsHeight()/2)
dx=Curve((MouseX()-gx)/4.0,dx,3.0/AppSpeed())
dy=Curve((MouseY()-gy)/4.0,dy,3.0/AppSpeed())
MoveMouse(gx,gy)
camerapitch=camerapitch+dy
camerayaw=camerayaw-dx
camerapitch=math.min(camerapitch,90)
camerapitch=math.max(camerapitch,-90)
fw.main.camera:SetRotationf(camerapitch,camerayaw,0,1)

movespeed=6
movesmoothing=10
if controller:IsAirborne()==1 then
	movesmoothing=200
end

--Player movement
move=Curve( (KeyDown(KEY_W)-KeyDown(KEY_S))*movespeed,move,movesmoothing)
strafe=Curve( (KeyDown(KEY_D)-KeyDown(KEY_A))*movespeed,strafe,movesmoothing)

--pick=CameraPick(camera,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,1000.0),0,0)
local pick = LinePick(EntityPosition(fw.main.camera, 1), EntityPosition(cube, 1), 0, 0)

if pick~=nil then
	pick_posX=pick.position.x
	pick_posY=pick.position.y
	pick_posZ=pick.position.z
	pvalue = pick.entity:GetClass()
end


--Use objects
if KeyHit(KEY_E)==1 then

	if pick~=nil then
		repeat
			if pick.entity:GetClass()==ENTITY_MODEL then
				break
			end
			pick.entity=pick.entity.parent
		until pick.entity==nil
		if pick.entity~=nil then
			pick.entity:SendMessage("use",controller,0)
		end
	end
end

--Update controller
controller:Update(camerayaw,move,strafe,jump,40,10)

fw:Update()

if KeyHit(KEY_F)==1 then
	flashlight:SetState(1-flashlight.state)
end

--Position camera
camera:SetPositionf(controller.position.x,controller.position.y+0.8,controller.position.z,1)

time=AppTime()
gunfirefrequency=80
gunswayspeed=0.001*20.0
gunoffset = gunpos:Copy()
gunswayamplitude = 0.02
if KeyDown(KEY_W)==1 or KeyDown(KEY_D)==1 or KeyDown(KEY_A)==1 or KeyDown(KEY_S)==1 then
	gunswayamplitude = 0.03
	gunswayspeed=0.005*20.0
end
smoothedgunswayamplitude = Curve( gunswayamplitude, smoothedgunswayamplitude,8.0  ) 
smoothedgunswayspeed = Curve( gunswayspeed, smoothedgunswayspeed,8.0 ) 
if smoothrecoil<0.001 then
	guntime = guntime + AppSpeed() * smoothedgunswayspeed * math.max(0.0,1.0 - smoothswaydamping)
end
gunoffset.z = gunoffset.z - smoothrecoil * 0.05
--smoothedgunswayamplitude = smoothedgunswayamplitude * (1.0 - smoothswaydamping)
gunoffset.x = gunoffset.x + math.sin( guntime ) * smoothedgunswayamplitude * gunscale
gunoffset.y = gunoffset.y + (1.0-math.cos( guntime*2.0 )) * 0.005 * gunscale-- * math.min(1.0,1.0 - smoothswaydamping))
vwep:SetPosition( gunoffset )
recoil = recoil-0.1
swaydamping = math.max( swaydamping - 0.05, 0.0 )
recoil = math.max(recoil,0.0)
smoothrecoil=Curve(recoil,smoothrecoil,3.0)
smoothswaydamping = inc( swaydamping ,smoothswaydamping,0.01 )
gunlight = math.max( gunlight- 0.2, 0.0 )
lightsmoothing =gunlight-- Curve(gunlight,lightsmoothing,8.0) 
muzzleflash:SetColor(Vec4(1.0*lightsmoothing,0.6*lightsmoothing,0.0,1.0))
if lightsmoothing <0.01 then
	muzzleflash:Hide()
end
if MouseDown(1)==1 then
	if AppTime()-lastfiretime>gunfirefrequency then
		recoil = 1.0
		lastfiretime=AppTime()+math.random(0,20)
		gunswayspeed=0.0
		gunlight = 1.0
		source_gunshot:Play()
		source_gunshot:SetPitch(1.0 + (math.random()-0.5)*0.05 )
		swaydamping = 1.0
		muzzleflash:Show()

		CreateBullet(vwep:GetPosition(1) , fw.main.camera.mat:K():Scale(300))

	end
end

UpdateBullets()

flashlight.light:SetPosition(fw.main.camera:GetPosition(1))
flashlight.light:SetRotationf( curveangle( fw.main.camera.rotation.x, flashlight.light.rotation.x, 3.0/AppSpeed() ), curveangle( fw.main.camera.rotation.y, flashlight.light.rotation.y, 3.0/AppSpeed() ) )
flashlight.light:Movef(-0.07,-0.04,0.02)

fw:Render()
DrawText(pick_posX,0,100)
DrawText(pick_posY,0,120)
DrawText(pick_posZ,0,140)
DrawText(pvalue,0,160)
Flip(0)

end

controller:Free()
vwep:Free()

ShowMouse()

 

I don't know... without seeing useable code to see exactly what you are doing I am just guessing... maybe its a problem with your positioning if there is a collision, maybe its an issue with the unnecessary pivots? why not just parent the camera to the player and be done with it?

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Because linepick returns a point that is slightly still inside the model. If I just parent the camera itself you see slightly inside the model that came between the 2 points. Because of this I do a MoveEntity() of the pivot slightly forward and then position the camera at the pivot. If I did this directly on the camera you would see it happening and create a strange jerking movement.

 

The reason I need the player pivot is because when you hold the left mouse down it rotates around the player. To do this the pivot does the rotation and not the player character. The pivots are needed to create a smooth professional looking 3rd person camera. They are very necessary.

 

 

I'll try your code above to see what it's doing and if it's a test.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...