# Draw box (like a bridge) between 2 points

## Recommended Posts

Hey guys,

I found this playground which draws a cylinder between 2 points: http://www.babylonjs-playground.com/#1RWE59#12

I'm hoping someone can shed light on how to do this same trick with a rectangle.

This is the closest I've been able to come

##### Share on other sites

Oh right! The object takes width,height, depth! Thanks adam!

##### Share on other sites

So close! Just need to "twist" them to be "flat".

- not sure how to describe flat, but hopefully this picture will help

##### Share on other sites

Created a playground with the issue I'm working through now:

##### Share on other sites

I would do some reading on vectors...

##### Share on other sites

http://www.babylonjs-playground.com/#1RWE59#61 has exactly what I'm after. Seeing some twisting in my implementation, depending on where I place them, probably related to the world position.

I was heading down the path of adjusting rotation.y, but missed the swap of width and depth. I was hard coding the rotation.y and trying multiple values to see how it would affect it.. Your levelBox function is obviously much more appropriate

Good news is that this still works well with physics.

@Pryme8 I've learned so much from this forum, and I'm focusing on Vectors now.

Thanks for everything guys

##### Share on other sites

Actually http://www.babylonjs-playground.com/#1RWE59#61 does show the same twisting, its just much less noticeable.

Added a 3rd sphere, and an OFFSET variable to make it more obvious when they are further apart: http://www.babylonjs-playground.com/#1RWE59#62

Still working through it obviously, but wanted to post the update that while the levelBox function certainly helps - there is still a slight twist.

##### Share on other sites

It has to twist like that because they are not on the same plane.

Take a look at this one where I place the red sphere on y = 0:

edit:

I think you're right.

##### Share on other sites

I forgot to normalize the vector.

##### Share on other sites

Thats it! Where is the "buy this man a beer" button?

##### Share on other sites

I had to change the function because in some cases you have to add the angDiff and other cases you have subtract (acos dot wasn't good for this).

##### Share on other sites

I noticed this also, forgot to come back and mention. But I solved for it by checking txaxis.x being negative. Thanks for the update, I'll try with both versions to see what difference it makes.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.