Jump to content

parenting entities


Rick
 Share

Recommended Posts

So I'm trying to parent one pivot to another. I then make cubes and set the cube position to the entities so I can validate things look right. In the code below my blue cube doesn't move when my red cube moves. What am I missing?

 

function Spawn(model)
local entity=base_Spawn(model)
entity.model=model

entity.cameraPivot = CreatePivot()
entity.playerPivot = CreatePivot()
entity.playerPivotCube = CreateCube()
entity.cameraPivotCube = CreateCube()

entity.playerPivotCube:SetColorf(255, 0, 0)
entity.cameraPivotCube:SetColorf(0, 0, 255)


-- make the player pivot the camera pivots parent so it moves with the player pivot
EntityParent(entity.cameraPivot, entity.playerPivot)
return entity
end

function Update(world)
-- must be in game mode
if(GetGlobalNumber("game") == 1) then
	-- update the player pivot with the location of the target(0)/playerPivot
	local model
	local entity

	for model,entity in pairs(entitytable) do
		local t = GetEntityTarget(model, 0)	-- this is the player

		-- the pivot to follow the player around
		PositionEntity(entity.playerPivot, EntityPosition(t))
		PositionEntity(entity.playerPivotCube, EntityPosition(entity.playerPivot))

		PositionEntity(entity.cameraPivotCube, EntityPosition(entity.cameraPivot))

		-- set the camera position to the camera pivot position. since this parent is the playerPivot it will follow
		--PositionEntity(fw.main.camera, EntityPosition(entity.cameraPivot))
	end
end
end

 

 

And in my example Target 0 is the monster truck. I see the red cube follows the truck but the blue cube stays at the origin.

Link to comment
Share on other sites

for the player, you are setting the position of the pivot first then the cube position based on the pivot.

 

for the camera, you are setting the position of the cube to the pivot, then setting the camera to the pivot... so how is this making the cube follow the camera?

 

shouldn't you set (better yet parent it) the pivot to the camera's position, and then set the blue cube to the pivot position...

 

its hard to tell with out actually seeing this in action and just guessing on how your camera is being controlled...

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

You can actually forget about the camera stuff it's commented out for now. Just trying to get the blue cube to move with the red. That camera stuff isn't correct.

 

 

shouldn't you set (better yet parent it) the pivot to the camera's position

 

The camera will be set to the pivots position. The pivot will be controlling where the camera goes. When it's all said and done.

Link to comment
Share on other sites

That doesn't seem to be working. I'm trying to parent 1 pivot to another. Then when I move the parent pivot the child pivot should move with it. I create 2 cubes that set their position to each pivot so I can see it in motion. The red cube is the parent and the blue is the child, but when I move the red cube the blue doesn't go with it.

 

function Spawn(model)
local entity=base_Spawn(model)
entity.model=model


entity.cameraPivot = CreatePivot()
entity.playerPivot = CreatePivot()
entity.cameraPivot:SetParent(entity.playerPivot, 1)

entity.playerPivotCube = CreateCube()
entity.cameraPivotCube = CreateCube()

entity.playerPivotCube:SetColorf(255, 0, 0)
entity.cameraPivotCube:SetColorf(0, 0, 255)


       -- offset the child pivot to start with	
MoveEntity(entity.cameraPivot, Vec3(0, 0, 5))
PositionEntity(entity.cameraPivotCube, EntityPosition(entity.cameraPivot))
return entity
end

function Update(world)
-- must be in game mode
for model,entity in pairs(entitytable) do
	MoveEntity(entity.playerPivot, Vec3(0, 0, -.05*AppSpeed()))

	PositionEntity(entity.playerPivotCube, EntityPosition(entity.playerPivot))
	PositionEntity(entity.cameraPivotCube, EntityPosition(entity.cameraPivot))
end
end

Link to comment
Share on other sites

Maybe it's the PositionEntity call that's not working. Try entity.cameraPivotCube:SetPosition(entity.cameraPivot:GetPosition(1), 1) or similar? Why not just parent the cubes to the pivots instead of manually moving them?

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

ZBrush - Blender

Link to comment
Share on other sites

The cubes are just here to show me where the pivots are since pivots don't have any graphical representation. I can't just parent them because this is my 3rd person camera and my camera will follow the position one of the pivots and parenting it doesn't work right as it introduces an artifact when the camera collides with models. I did this in C++ but just trying to make it an object in lua so it's very easy to add to any model.

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...