Search the Community
Showing results for tags 'local space'.
-
Hello Everyone, I've been trying to go at this on my own but I've been stuck for days trying to add some basic AI to a cube. Play the FPS style game here on desktop or mobile: https://xtreemze.github.io/Ballistic you can find the full JavaScript here: https://github.com/xtreemze/Ballistic/blob/master/js/master.js Controls: touch the cube button on the bottom to shoot ice cubes and use standard universal camera controls to move and look around. Here's where I'm stuck: I got window.cube to jump and look at the camera but now I need a force to push the window.cube to move towards window.camera. I just can't figure out how to setLinearVelocity in the local forward direction of window.cube. redMesh is the Mesh of window.cube and redCube is the impostor of redMesh. (Also would be nice if the lookAt() rotation was eased or slowed down so it wouldn't seem so sudden but that's a lower priority.) Here's the part of the code that controls the cube AI and thanks in advance for taking a shot at this! // Global Scope Declarations for Console Tests window.button = button; window.cube = redCube; window.cubeMesh = redMesh; window.camera = camera; // Red Cube turns to look at camera const rotateCube = function rotateCube() { redMesh.lookAt(camera.position); }; // Cube Movement towards Camera ??? const jump = new BABYLON.Vector3(0, 5, 0); const front = new BABYLON.Vector3(0, -10, 0); const goForward = redMesh.getDirection(front); const moveCube = function moveCube() { redCube.setLinearVelocity(jump); rotateCube(); // redCube.setLinearVelocity(goForward); }; window.setInterval(moveCube, 2000);
- 8 replies
-
- ai
- local space
-
(and 1 more)
Tagged with: