Jump to content

Attaching camera to animation


AggrorJorn
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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