Jump to content

Smooth setTarget


meteoritool
 Share

Recommended Posts

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 !

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 it
http://www.babylonjs-playground.com/#4HUQQ#89


Best

Edited by Nabroski
playground
Link to comment
Share on other sites

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 B)

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 :huh: ? How to get the camera.rotation to the obj.position ?

var anim = BABYLON.Animation.CreateAndStartAnimation("anim", camera, "rotation", 30, 100, camera.rotation, ???????, 2);

Link to comment
Share on other sites

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 :/

 

Link to comment
Share on other sites

On 4 juillet 2016 at 6:21 AM, Nabroski said:

yes, now i see it, its probably something you have to investigate in

http://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 :ph34r:
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 ...

Link to comment
Share on other sites

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 ^_^ !!!
 

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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...