meteoritool Posted July 1, 2016 Share Posted July 1, 2016 Hi all ! I wonder how to smoothly turn the camera towards the target when the function .setTarget() is executed. In the following playground, clicking on the box will make the camera look at it:http://www.babylonjs-playground.com/#4HUQQ#66 How to make the transition smooth ??? Ideally there would be : .setTarget(target, time) in the library but I don't know how to achieve that :/ Any idea on how to do that ? Thx ! Boz 1 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted July 1, 2016 Share Posted July 1, 2016 You just have to animate your target point, the same way you would animate any object. Boz 1 Quote Link to comment Share on other sites More sharing options...
Boz Posted July 1, 2016 Share Posted July 1, 2016 So you recommend using animation on an object each time we want to make a camera smooth transition ? Like creating an object, set it as target, make it invisible and start animation ? Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 1, 2016 Author Share Posted July 1, 2016 53 minutes ago, Vousk-prod. said: You just have to animate your target point, the same way you would animate any object. I tried this, but when the camera has no initial target, I don't know how to properly set the first target according to the camera actual rotation ... Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted July 3, 2016 Share Posted July 3, 2016 On 07/01/2016 at 8:13 PM, Pouet said: So you recommend using animation on an object each time we want to make a camera smooth transition ? Like creating an object, set it as target, make it invisible and start animation ? Yep, you can do like that. I think this is the most efficient and usefull (in most case the camera should look at some precise point, easily identifiable as a moving object) You can also animate directly the target property, by creating your own animate function that creates and launch direct animation on the target property of the camera each time you need a smooth movement. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 3, 2016 Share Posted July 3, 2016 your playground works perfect, you exectue a code on a mouse click. looks pretty to play with keep on updating if you got some news. this works for mehttp://www.babylonjs-playground.com/#4HUQQ#78 best Boz 1 Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 3, 2016 Author Share Posted July 3, 2016 2 hours ago, Nabroski said: this works for mehttp://www.babylonjs-playground.com/#4HUQQ#78 interesting method ! I'll look into it ! Here's my first try, but that doesn't do the stuff flawlessly ...http://www.babylonjs-playground.com/#4HUQQ#83 camera.getTarget() returns the camera.position when unset. Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 3, 2016 Author Share Posted July 3, 2016 Hello ! I'm trying to use ray tracing :http://www.babylonjs-playground.com/#4HUQQ#88 But that doesn't quite work :/ How can I translate the camera.rotation to a ray.direction ??? Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 3, 2016 Share Posted July 3, 2016 (edited) Hello @meteoritool I'm not quite sure what you are trying to archive. With 1 single line of code as in my example you get a nice zoom in to the object effect, when you want you also can add the rotation - with a single line of code. For any reason you catch fire to go with setTarget. And now you start to implement you own Settarget function. whitch is good, i also have to idea how to pick with rays, and don' t want to rewrite your achievements. Maybe it's gonna be the one for an update on github to the current one. Position, Rotation, setTarget,getTarget all all them are a Verctor3. Keep on experimenting. Looks promising The Problem with setTarget is that it locks your mouse to the target as well, so you have to care about ithttp://www.babylonjs-playground.com/#4HUQQ#89 Best Edited July 3, 2016 by Nabroski playground meteoritool 1 Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 3, 2016 Author Share Posted July 3, 2016 Thanks a lot for looking into it ! I haven't used the BABYLON.Animation so far and I think I've learned something crucial today thanks to your PG What I'm trying to achieve is to make the camera "look at" the object, not moving the camera.position. But I still don't know what to put there ? How to get the camera.rotation to the obj.position ? var anim = BABYLON.Animation.CreateAndStartAnimation("anim", camera, "rotation", 30, 100, camera.rotation, ???????, 2); Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 4, 2016 Author Share Posted July 4, 2016 EDIT: I made a little mistake in my previous PG ... I had noticed that camera.getTarget() returns the camera.position + a value between -1 and 1, and I thought that might be interpreted as a .direction. Hence the ray.direction = camera.position - camera.getTarget() http://www.babylonjs-playground.com/#4HUQQ#90 Now it works, and you can visibly see what's going on. The behavior is weird though :/ when you're looking above the crates, everything works, but when you're looking under the crates, the target's origin seems not to come from the right intersection with that sphere created :/ And if you get too close to the crate, the script crashes :/ Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 4, 2016 Share Posted July 4, 2016 Hello yes, now i see it, its probably something you have to investigate inhttp://www.babylonjs-playground.com/#4HUQQ#96 best Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 5, 2016 Author Share Posted July 5, 2016 On 4 juillet 2016 at 6:21 AM, Nabroski said: yes, now i see it, its probably something you have to investigate inhttp://www.babylonjs-playground.com/#4HUQQ#96 @Nabroski I considered using a mesh.lookAt() but my first researches had that strange word QUATERNION that I don't want to investigate lol I finally got something working but this is ugly http://www.babylonjs-playground.com/#4HUQQ#107 I use a setTimeout lol Maybe the proper way of this method would be to use a virtual camera to setTarget() the obj, then apply the virtual camera.rotation to the actual camera.rotation. In my example I use the actual camera and make it move very fast to get the values then apply them slowly lol I'm sure this is not the best way though ... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 5, 2016 Share Posted July 5, 2016 Why using setTimeout? http://www.babylonjs-playground.com/#4HUQQ#108 Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 6, 2016 Share Posted July 6, 2016 just to provide this playground with slightly different visuals http://www.babylonjs-playground.com/#4HUQQ#121 Boz and meteoritool 2 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 6, 2016 Share Posted July 6, 2016 lol ok:D Quote Link to comment Share on other sites More sharing options...
meteoritool Posted July 10, 2016 Author Share Posted July 10, 2016 On 5 juillet 2016 at 0:26 AM, Deltakosh said: Why using setTimeout? It didn't seem to work without setTimeout (initial rotation and goal rotation returned the same value) I have no clue why >_< !!! Thanx ! This function was needed because I'm making a scene with fps style camera, and I use it when 'cinematic' moments happen, to look at an object or character. Now the flaw of this function is that if the camera is in movement while targeting, it becomes wrong ... phew, some brainwork ahead !!! 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.