Jump to content

Player movement problem?


Aerion
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by JohnK
Corrected link
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...