Closed Cghost96 closed 4 years ago
Well, the up
vector exists for exact this purpose (meaning to configure the game entity's local coordinate system). So I think you are doing it correctly.
Instead of checking the rotation of the robot in the animation loop, there might be the option to do this on certain events. However, this of course depends on your application.
Hi,
I wanted to hear if someone have any ideas for a better solution than the one i’ve come up with.
Background of the problem:
I’m making a 3D-simulator for a company. Basically it’s a water-pool and in the pool there will be robots that can either follow a 2D preprogrammed route/path or the robots can be controlled like an ROV in 3D-space. I’m planning to use THREE.js combined with YUKA.js for the simulator and so far it looks very promising.
Illustration of the pool with drawn world space axes and a preprogrammed route/path (on “Floor 1”):![image](https://user-images.githubusercontent.com/68368892/87635531-82d3b100-c73f-11ea-8775-1e4ab2d0bf5d.png)
Illustration of two of the robots with AxesHelper and ArrowHelper added to them:![image](https://user-images.githubusercontent.com/68368892/87635553-8d8e4600-c73f-11ea-86a7-d59803973a89.png)
Explanation of problem:
The robots are YUKA Vehicles and I’m using FollowPathBehaviour and OnPathBehaviour. When the robot follows a path on the floor (i.e. when the y-axis of the robot and the world y-axis points in the same direction and the robot.up-vector is positive y) there’s no problem; the robot rotates/orients itself as it should:
The problem occurs when I want the robot to follow a 2D-path on one of the pool walls. I want the robot y-axis to always be orthogonal to the surface it’s on and to point inwards in the pool. To do that I set the robot.up-vector to x, y or z based on what surface in the pool it is running on. Here I’ve created a 2D-path on “Outlet 1” and set the up-vector to positive x. As you can see the robot “flips” after the turn to make sure the x-axis always points in positive world y-axis, I want to avoid this flipping.
My solution:
The solution I’ve come up with is to check the rotation of the robot in the render-loop and change the up-vector based on that. It works but I wanted to check if someone have any idea for a better solution? Is there any way to “trick” the robot into thinking that the world x-axis or z-axis is up instead of world-y, and then always let the up-vector be positive y locally?