Asagi Posted September 21, 2018 Share Posted September 21, 2018 Hi! Tell me please, is it difficult to implement the control of the ship as a link in the video? Tell me how to proceed? Or examples that can push the right path. I've been trying to copy this control model for two days already. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted September 21, 2018 Share Posted September 21, 2018 Hi Asagi. My initial thoughts is that there is an invisble mesh parented to the fighter ship... and positioned in front of the ship... SOME distance. Then, something similar to a BABYLON.FollowCamera is targeting that invisible mesh. Notice the followCamera... .lockedTarget property - set the camera's .lockedTarget to the invisible mesh. [a mesh object] .radius property - set the distance that the camera should follow-at. [a positive number] .heightOffset property - to keep the camera a bit higher than ship/invisible-target. [a number - perhaps positive or negative] .rotationalOffset property - potentially useful... just experiment with it. [a number - perhaps positive or negative] .inertia and .speed - also potentially-useful properties. [also numbers, likely positive-only] I would say... 'target' your experiments in this 'direction'. (arr arr arr) Stay tuned, others may reply soon. Quote Link to comment Share on other sites More sharing options...
QuintusHegie Posted September 22, 2018 Share Posted September 22, 2018 (edited) The camera is apparently not following your space ship but the other way around. Have you looked into the mesh.lookAt() and scene.pickMesh() functions? You can look up the code behind it on GitHub. Instead of instantly looking your mesh (camera) at the target (pickedMesh.position), the transition is smoothed to a max delta angle per frame. If there's no mesh (e.g. enemy ship) under your cursor, no problemo. You can still transform the pointed pixel back to a Ray cast from the camera by transforming 2D point using Camera view matrix to world 3D. This is basic 3D math and BabylonJS provides some default functions to transform positions and rotations to different spaces (CAMERA, LOCAL, WORLD). So the computation is translating the 2D cross hair position in camera space to 3D cross hair world space position. Your space ship is like the FollowCamera logic of inertia. It's following a point in front of the real camera used. You can see that clearly when turning and stopping turning: the ship smoothly transitions back to the center bottom of the screen. Finally the guns on your spaceship are then pointed to the 3D point that the screen cursor is pointing at. If there's a mesh under the cursor, that gives you the distance. If not, then you can default to a certain distance in Z-axis (e.g. near infinity). You can use mesh.lookAt() to target the guns to the 3D cross hair location. Again you can use interpolation (smoothing) to give the guns some time to aim at the new direction. Hope these tips help. If you solved it I would glad to hear about the solution. ? I'm looking for a similar aiming for my BabylonJS Model Train Simulator game, but then the Spaceship/guns is replaced with a Locomotive/crane. The above steps describe how I would start tackling this click-and-aim challenge. Q Added: Check out this post from @renjianfeng : for inspiration and help: Edited September 22, 2018 by QuintusHegie added reference to other babylonjs developer that is solving the same problem Quote Link to comment Share on other sites More sharing options...
Asagi Posted October 2, 2018 Author Share Posted October 2, 2018 Hello everybody! Help Wanted. It does not work to realize this kind of camera.You can somewhere at least a similar example on BabylonJS? Quote Link to comment Share on other sites More sharing options...
coolroar Posted October 2, 2018 Share Posted October 2, 2018 I've worked up a "flying through space" camera that might be applicable: https://www.babylonjs-playground.com/index.html#Q1RH6C I used the technique in my ZOOM game at jounce.space. Here is a thread where Phuein is trying to create a camera rolls so "up" is always in the same direction: and here: Good luck! ? ☘️ Quote Link to comment Share on other sites More sharing options...
Asagi Posted October 9, 2018 Author Share Posted October 9, 2018 I need help. I have a some object like this. It's mesh of spaceship. And when i try add rotation, babylonjs give some error: Object structure. Object is 3d model imported from babylon file. (converted from blender3d) What i do wrong? Thanks! Quote Link to comment Share on other sites More sharing options...
Guest Posted October 9, 2018 Share Posted October 9, 2018 Hello, rotate expects vector3 parameters: http://doc.babylonjs.com/api/classes/babylon.transformnode#rotate Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.