so I want my camera to be stationary aka not changing its position but keep focussing a moving target. So the camera should only rotate with the moving target always in center of the screen (until it disappears behind an object).
The camera should not be user controlled.
I tried using the target property but as far as I understood setting this property on a FollowCamera/FreeCamera will lead to the camera moving in a set distance to the set target instead of being stationary and only rotating.
Doesnt the ArcRotateCamers rotate/move around the target obeject? I just want the camera to stay in place and only change its y-rotation so the moving target object stays in the center of the screen. It is more like an inverted ArcRotateCamera with the camera in the middle tracking an object which is moving around it.
Can you prepare a Playground with the moving object? I bet we can figure out it no time which camera is suitable for you as well the underlying implementation should not cause any problems.
Within the playground I achieve the desired behavior by using a FreeCam and setting the lockedTarget property to the mesh to focus. So I guess this should also work within my scene. I just need to figure out why thatās not the caseā¦
Seems like the TransformNode parented to the camera is causing the problem. Its rotation and translation seems to interfere with setting the lockedTarget property.
Any solution to this? Iām not that familiar to matrices and views.
I could have misunderstood it so my apologies if this is.
Iām just wondering what this is with this transform on the y-axis?
You want to follow/target the object so that it is always in the center of screen, is that correct?
Yes, you are correct.
I think I need to give some more context.
So in my project the user (camera) is walking down a path. At the same position as the camera there are two lights being placed, illuminating the path in front. Therefore camera and lights are being parented to a TransformNode (which is then animated along the path ā āwalkingā animation).
Along the path āeventsā will happen. For example a bat flying by, things crossing the path, etc. ⦠At those event-points the āwalkingā animation will pause and the camera should track the āeventā (for example track the bat flying by and disapearing in the dark) before resuming to walk down the path after the event ended.
Thatās why I added the TransformNode into the playground and changed the y-rotation, because in the project rotation and position of the player (Camera + Lights) are constantly changing. And thatās when I found out that setting the lockedTarget property of the camera while also having a rotation at the parented TransformNode will cause the camera to not track the object as planned.
The first thing that comes to my mind is removing the parented TransformNode, instead directly parent both lights to the camera object and animate the camera object instead of the (now removed) TransformNode?
Any thoughts? Or is there a work around where I can multiply some matrices and vertices to get the correct position to point at (but then again the events position is animated so the cameras target position would have to change as well)?
Interestingly not setting the lockedTarget property but the target property instead leads to the correct result for the āinitial focusā but wonāt track the objectās movement.
Maybe itās because setting the lockedTarget property disables panning?
Define the current target of the camera as an object or a position.
Please note that locking a target will disable panning.
So I found a workaround. When the object-to-trackās animation is started I gonna add and onBeforeRenderObservable which is setting the cameraās target property over and over again as long as the objects animation isPlaying. After the animation ended i remove the observable.
Iām happy you found the solution on your own because - thanks for the context - but this caused me even more confusion and I would have had many more questions, like:
So, is it actually a first person camera view? the camera is the player and moves like in an FPS? He follows a path, does this mean movements are restricted? When the event occurs, the user inputs/view is frozen and the āfollow eventā behavior/animation kicks in? Once the event is over, freelook and user movement inputs are restored (with or without restrictions)? ā¦
Though, now that you found your solution (GJ ), you donāt have to answer, of course ⦠but may be, if itās not too much effort for you, you could share your logic for other users having a similar use case? That would be great (not a request, just a suggestion). Meanwhile, have a great day and GL with your project
Iām sorry for the confusion
Sure, Iāll happily share my ālogicā here to help others (although I do not know if my solution is the ābest caseā or even performant. But Iāll try to give some more information:
In my project a first person camera (representing the user) is animated along a path (I will call this the āwalkingā animation). This camera has - for the moment - no controls at all (not during the walking animation as well as not during the events that happen along the path), although some slight rotation (like looking left/right) might be added. Because the user has no influence on the walking animation, the āwalking down a pathā is more like an experience. At some (for the user random) points along the path the walking animation will pause and an āeventā will happen. Those events are objects crossing the path from side to side or just take place right next to the camera. The moment an event is triggered the camera should pan/rotate towards the event and track it as long as the event lasts so the events origin is always in the center of the screen. After the event has disappeared the camera pans back down the path and the walking animation resumes to play.
Maybe itās easier to understand if I use a made up example:
Imagine itās night, youāre walking down a path through the woods. Because you are scared you do not want to /can not look left/right or stand still. Then suddenly you hear noise nearby. You automatically stop walking and look towards the noise. The source of the noise is a small hedgehog which is now crossing your way from one side of the path to the other. You watch it pass by, until it disappears and then continue your journey down the path through the woods. This keeps going until (maybe) you reach the end of the woods.
Yes I know, everyone would start running when the noise appear
Although I think using/setting the lockedTarget property might actually be the best solution it doesnāt work for me as the camera is always pointing in the opposite direction (like in my first playground). Using the target property lets the camera point in the correct direction (but wonāt track the object as the property is only made for Vector3). I do not know if this is the case because setting the lockedTarget property breaks camera panning, but I found a workaround (as I said I have no clue whether this is a āgoodā solution regarding performance, etc.): the moment an event triggers (and therefore the walking animation pauses) I create a panning animation for the camera towards the events position. After the animation ended I register an Observable for onBeforeRenderObservable which is re-stetting the cameras target property over and over again (with the eventās current position) so it is tracking the event. The moment the eventās animation ends a new camera panning animation is created and played so the camera is pointing down the path again. After this animation the āwalkingā animation resumes.
Hope this gives some more clarification. Thanks for all your help and input.