AggrorJorn Posted August 11, 2010 Share Posted August 11, 2010 I am trying to attach my camere to an animated box. The animation of the box works but the camera doesn't update on its position. I tried using SetParent and updating the camere position by getting the box's position each frame. Inside main loop I have the following: if playAnimation == 1 then frame = (AppTime()/20) % 1030 + 1 path:Animate(frame, 1, 0, 1 ) fw.main.camera:SetPosition(path:GetPosition(1)) if frame >= 1029 then playAnimation = 0 end During the animation I can not move my camera. However, once the animation is done, I can start moving my camera by using the arrow keys. This would indicate that the position of the box's pivot remains the same while the mesh itself is somewhere else. How can I get the mesh's position during the animation and update the camera to that position? Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 11, 2010 Share Posted August 11, 2010 is "path" the animated mesh or is it a bone of the mesh? Setting the camera to a bone of the mesh should work. 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...
AggrorJorn Posted August 11, 2010 Author Share Posted August 11, 2010 It is an animated mesh. I'll replace the mesh with a bone and palce the camera on the bones position during the animation. thx Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 11, 2010 Author Share Posted August 11, 2010 Well the camera is now being updated with the animation (with some tweaking). But there is one different problem: When you start the program and wait a couple of seconds and then press the play button, you will notice that the animation doesn't start from the beginning. It is like the animation is secretly counting the frames even though it is not playing the animation. Every time you wait after the animation is finished and you press play you will see it starts later in the animation. Have a look at the scene. Just run the engine.exe. The start.lua files contains the code. Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 11, 2010 Share Posted August 11, 2010 ok how about this? --Play the animation if playAnimation == 1 then frame = frame + AppSpeed() path:Animate(frame, 1, 0, 1 ) if frame >= 1029 then playAnimation = 0 frame = 0 end end 1 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...
AggrorJorn Posted August 11, 2010 Author Share Posted August 11, 2010 That seems to work okay. And the AppSpeed also takes care of the same animation speed. Thank Macklebee. +1 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 16, 2010 Author Share Posted August 16, 2010 Small update on this. The camera animation goes fine and everything but after the animation, things start to go wrong. The camera rotates and moves along with the bone from the animation (that is okay). However because the camera is parented, the actual Vec3 position and rotation are not being updated during the animation. When the animation is complete and I want to place my camera somewhere in the scene, then the positions from the bone are being combined with the newly set positions. I think that this happens because of the parenting. I tried removing the object with the animation but that resolves into a crash without any further information. Is there another way for me to unparent the camera from the bone-animation? Or thoughts on things that I might try. here is some code I am using. (note that the code is distributed in functions and is not being run right after each other.) parenting and adjusting camera to the bone-animation: animation-start = level1:FindChild("animation_Start") bone1 = animation-start:FindChild("bone1") fw.main.camera:SetParent(bone1) fw.main.camera:SetPosition(Vec3(0,-3,0)) fw.main.camera:SetRotation(Vec3(0,260,0)) During the animation, the camera position remains 0,-3,0 and the rotationis 0,260,0. play the animation: --Play the bone-animation if bone-animation == 1 then frame = frame + AppSpeed() / 10 animation-start:Animate(frame, 1, 0, 1 ) if frame >= 1023 then bone-animation = 0 frame = 0 Level1PlayerStart() end end After the animation is done, find playerStart. start = level1:FindChild("start") fw.main.camera:SetPosition(start:GetPosition()) The last line doesn't seem to work at all. The camera does not get positioned at the 'start' enity. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 16, 2010 Author Share Posted August 16, 2010 unparenting in Lua is: entity:SetParent(nil) 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.