Aerion Posted July 28, 2017 Share Posted July 28, 2017 Hi all. I've been searching the web for the past 24+ hours & cannot seem to find a demo where when moving a 3d object and attaching a follow camera ( chase cam ) to the player, i can't seem to find a demo which allows the object to move in the same direction the chase camera is facing. How would you go about doing that? Thank You all! <3 Mythros Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 28, 2017 Share Posted July 28, 2017 Hi again, M. Should search playgrounds, not web. Anyway... https://www.babylonjs-playground.com/#2CPTBX#18 Work-in-progress. Click-on-canvas to focus, and then... left-right mouse-dragging will turn the box/player... using box.rotate(), which is a "Quaternion"-based rotation. It is slightly different than using the box.rotation property. We'll talk about all that, later. Also, WASD keys are active. A & D keys are also box rotaters, also using box.rotationQuaternion (box.rotate). See the two funcs in lines 38-46? They are used by both mouse-drag turning AND A/D key turning. They also allow individual rotation speeds. In lines 57 and 64, we can see the rotation speeds for the A/D keys. In lines 111 and 113, we can see the mouse-drag rotation speeds. W and S keys are forward/backward, and they move (translate) the box forward/backward PER the current box rotation. A special Deltakosh-coded transformer func in lines 31-36... make that possible. So, you can hold down the W/S keys and steer with mouse-dragging left/right, and it all works pretty good, eh? Currently I have nothing "wired-up-to" mouse-drag forward/backward, but that can be activated, too. You could use it for moving box forward/backward, or for raising/lowering the altitude of the followCamera. There is still a problem, here. Camera is jittering/stuttering. You, me, and other forum helpers... can try to figure that out, soon. Also, this method will still make it difficult for player to slide down heightMap hills. (Sliding down hills was mentioned in another Mythros thread.) I have been trying to think-up ways to make hill-sliding easier. During forward slides down hills, followCamera will stay behind player nicely. But for sliding down a hill backwards... or sideways... the followCamera MIGHT swing-around, trying to keep itself behind the direction of player-sliding. Not sure if that will be good or not. For sliding, we are going to need some fancy code that senses the amount of "slope" of the heightMap... beneath the player's position... and moves the player based-upon that slope. I think it can be done... but I will need more think-time, and/or some assistance from the BJS "big dogs". I also want to allow things like W and A keys held at same time (a forward-moving left-turn). I'm not sure how to do that yet, either. Meantime, we have SOMETHING, right? We're on our way, eh? What an adventure! Stay positive... we'll keep working on it and having fun. Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 28, 2017 Share Posted July 28, 2017 (edited) 5 hours ago, Wingnut said: I also want to allow things like W and A keys held at same time (a forward-moving left-turn). I'm not sure how to do that yet, either https://www.babylonjs-playground.com/#102TBD#31 Lines 138 to 149 then lines 191 to 207 for an example of use. Not my idea somebody else was clever. Got the idea of the web but cannot remember who or where. Edited July 28, 2017 by JohnK Corrected link Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Aerion Posted July 31, 2017 Author Share Posted July 31, 2017 Problem Solved for the most part! I now need to be able to turn / move at the same time! Then I'll mark this as complete! Thanks again! Mythros Quote Link to comment Share on other sites More sharing options...
Aerion Posted August 1, 2017 Author Share Posted August 1, 2017 This isn't solved... I didn't mark that.. That above Car example is way too difficult to understand. Quote Link to comment Share on other sites More sharing options...
JohnK Posted August 1, 2017 Share Posted August 1, 2017 Strange as only you should be able to mark it. However go to first post and edit it. You can then delete or change any tags. Want to know more about car example http://babylonjsguide.github.io/gamelets/Car_Driven If you just want more info on multiple key presses let me know. max123 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted August 1, 2017 Share Posted August 1, 2017 There is now an easier way to add wheels to a car and rotate using addRotation http://doc.babylonjs.com/overviews/how_rotations_and_translations_work#more-advanced-rotation example with car in this topic 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.