Jump to content

How to move object through a cube?


cartman
 Share

Recommended Posts

Thanks @Brandenburg! I'm trying to expand on this with two ideas:

1) Third-person perspective (following the sphere from behind). I did this demo with a FreeCamera: http://www.babylonjs-playground.com/#14EGUT#6 ... it's not perfect.

How do I make sure the view follows the sphere? I'd like the camera to always point forward (imagine a game where the user follows closely behind the sphere, and sees what the sphere sees) 

 

2) First person perspective. I basically used the FreeCamera, and matched the position of camera with sphere. Demo: http://www.babylonjs-playground.com/#14EGUT#7. How do I make sure the camera view is always looking forward? (imagine a game where the user IS the sphere).

 

Any ideas?

Link to comment
Share on other sites

I'm also thinking, perhaps it's easier to visualize the sphere as a box instead

http://www.babylonjs-playground.com/#14EGUT#8

This way, the problem is finding how to make the box rotate so that it's front face (head) is always moving towards the exit of the tube. Once that rotation curve is figured out, we can attach a FreeCamera to it to mimic the rotation.

Any ideas?

Link to comment
Share on other sites

cartman, if you use a 3D modeling software you can create animations on curves quite easily

Example here

A cube was animated on a path to move between the various objects in Blender, then the light and camera were attached to the cube with BJS

Always liked that example @adam :)

cheers, gryff :)

Link to comment
Share on other sites

Thanks @Brandenburg, elegant solution with the lookAt method. Very useful!

One thing I noticed, is that you're iterating through the indexes in the curve.

How would I slow down/speed up the movement of the cube (sphere), in this case? Is is possible via BABYLON.Animation?

 

 

Link to comment
Share on other sites

Yes, for some reason the cube kept jittering with animations so here it is with a new playground:

http://www.babylonjs-playground.com/#14EGUT#19

I am using a extra mesh (invisible) to get the rotation. If I could find the code for the lookAt method I could probably come up with my own method so that we would not need the extra mesh.

Let me know how it works, Brandenburg

Link to comment
Share on other sites

I'll tell you a secret ...

When the tube is constructed, a reference to its underlying Path3D is stored : https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.meshBuilder.ts#L777 in order to not reallocate the memory in case the tube would be morphed (it is intended to be morphed)

The path3D is a triplet (tangent, normal, binormal) associated to each point of the tube path. This triplet is a left-handed normalized system :-)

So no need to recompute it ... it's already stored in the tube instance. You can just use RotationFromAxisToRef(tangent, normal, binormal, ref) 

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