Rick Posted December 16, 2009 Share Posted December 16, 2009 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. Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 16, 2009 Share Posted December 16, 2009 perhaps you should try parenting the cubes to their pivot in the spawn instead of trying to update the position... Quote 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 More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 Yeah, but that shouldn't matter. The positioning works for the red cube just fine. Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 16, 2009 Share Posted December 16, 2009 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... Quote 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 More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 Is there an example of setting parents anywhere? I'm convinced it doesn't work via lua. Quote Link to comment Share on other sites More sharing options...
Niosop Posted December 16, 2009 Share Posted December 16, 2009 someThing:SetParent(otherThing) Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 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 Quote Link to comment Share on other sites More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 What's really interesting about this is it works if I just use the cubes instead of the pivots. If I make the parent of the blue cube the red one, it all works. So what's the difference with pivots? hmmm Quote Link to comment Share on other sites More sharing options...
Niosop Posted December 16, 2009 Share Posted December 16, 2009 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? Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted December 16, 2009 Author Share Posted December 16, 2009 hmm that did it. So what's the difference? What am I missing? The PositionEntity() and EntityPosition() works for the player pivot. [EDIT] Ah it's the 1's. For the child I need those but for the parent I didn't. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.