First Person movement script with Key and mouse bindings


(Cotaks) #1

Hello,

First Person movement script with Key and mouse bindings v2 (27-05-2018)

What this new version can do:

  • It lets you or the player set his own key and mouse bindings
  • There is no sliding down on slopes (player friction is set to zero as well)
  • Slope detection to alter forces and speeds
  • No more getting launching in air when you walk/run on/of a slope
  • The character can climb allot of angles at different speeds depending on the angle.
  • High physics substebs won’t be a problem anymore.

Default controls:

  • mouse to look around
  • A,S,W,D to move
  • SPACE to jump
  • SHIFT to run
  • K to open keybindings menu

Download:
first person movement with key and mouse bindings.blend (803.0 KB)

if you want the keybindings without the movement script, you can get it here: Key and mouse bindings

I hope you all like it,
Cotaks


Key and mouse bindings
Cotaks resources
(Asdfghjkl) #2

Thanks. I realy like it.


(Asdfghjkl) #3

Hello Cotax. I am using some of your scripts in my game and I realy like them. But i got some problems.

Its about the movement script:

  1. When I adjust the substeps in my game from 1 to 3 or more, the player begins to go up and down very fast. Its someting like a bug.

  2. When I am close to object for exempel a wall and try to jump while the “W” “forward motion” key is presset i cant jump.

Do you know how I can fix this problems?

Blend File- https://drive.google.com/file/d/0B9_cPB7Z-2Idd1p3aEdieUJfX3c/view?usp=sharing

Thanks for the help.


(Cotaks) #4
  1. no idea, i have set all physics from 1 to 5 substeps etc all works like it should be. (no chaking)

2.the first (big) player does how it should be, the other has the material disabled (how did you duplicate it? never seen it this way)
select the player box head to material, look at the name of the material, there is a little paper icon with a small arrow pointing to the right side (direct linked data block, make it local), click on it, now put friction on zero and at physics tab -> collision bounds hit compound.

no idea what you have done to be honest, you got a lot of errors in the console.


(Asdfghjkl) #5

Hello Cotax. Thanks for your replay. I imported the files in the hard way because I am a bit noob. I append some of the obejcts from your file and then copy and paste them and delete the appendet files with the blue surrounded lined “Not 100% sure how i did it” :). I am also a bit confused.

But about the BUG. I have looked in to your original file and there was that BUG too. I think its because the sensor object for the ground. But when I set the substeps more than 1 the player bagans to go up and down. I have also gif. – http://goo.gl/AD6DSv . I am not sure if you can see wath I mean. Its someting like bobbing UP and Down realy fast.

Thanks for your help and your scripts.

Sory if I disrupt / irritates you.


(Cotaks) #6

i found the error and indeed high substep with the sensor cube will make the player shake, strange but normally you dont need to increase the substeps, you can leave it as is.

to fix the problem if you need high substep, select the ground sensor cube, remove the groundcheck sensor
place the ground check sensor (with the exact same name) to the player cube and connect it with the movement script.

it will not bounce anymore, but movement behavior will change a bit.

Sory if I disrupt / irritates you.

not at all, if i can’t support my own ‘products’ then i should not have it posted here :wink: but to be really honest i attached that movement script to the keybindings as an example of how to do it and to show that it works (i dont even use that version my self, that’s why that version is not included in my sig).

I also checked all my other FPV and TPV setups (i always use a cube as sensor) and they don’t have the problem, i think this is a combo of an old blend in a new blender version, that script was made in 2.60 i believe.


(Cotaks) #7

ok Asdfghjkl pointed out that the player will shake when you set the substeps higher then default value.

To fix the problem (if you need high substep), select the ground sensor cube, remove the groundcheck sensor
place the ground check sensor (with the exact same name) to the player cube and connect it with the movement script.


(Jason van Gumster) #8

Moderation: Moved posts to this thread where they make a bit more sense. In the future, I’d rather not do this. Please just link to the other thread rather than request splits and moves.


(Asdfghjkl) #9

Thanks for the help!


(Asdfghjkl) #10

Sorry. I did not know.


(Cotaks) #11

Ok i did some more test related to the bouncing problem.

I do now know the official '‘bug’ it has nothing to do with the cube sensor, The problem is the way i build the anti slope sliding.
While the workaround i posted works, this is not the best thing to do, i will update a new blend and going to remove the anti slope sliding from it, so that you got a working example/blend with high sub steps.

@fweeb
Thanks for the time spent moving the post.

#edit
added v0.9 removed the texture to reduce file size, and removed the anti slope sliding.
I dont like it(at all), but if you really need high substeps there is a version for it now.


(Asdfghjkl) #12

Hello Cotax. Thanks for your replay and the spend time. I like the v0.9.

  1. The jump problem near wall is fixed, so when I am close to wall and try to jump the player wil jump correctly.

  2. When I have more substeps than 1 the player wil not Bounce.

But know I found another small problem. When I try to go up a hill or something that is sloped “fx. the orange object in your file”, the player goes too fast up. I made the angle of the slope smaller but the player was still able to climb.

I tried to edit the script and I deleted the “z = own.worldLinearVelocity.z” and replace it with “z = 0.0” and that worked for the slope in some cases, but know the player can’t jump.

Is there any easy way to fix it?

Thanks.


(Cotaks) #13

haha i knew that would come. thats why i said that i dont like that version :wink:
follow the thread in general discussion, ive asked there if there is a good way to stop the sliding.

but you can also let the collision check find a property on a plane and then put the no sliding on.
then you would only see it bouncing when standing on a slope if there is bouncing at all and you get the general feeling back.


(Asdfghjkl) #14

Thank you very much. It has been long discussion here and I wanted to thank you for your spend time.


(Cotaks) #15

Thank you very much. It has been long discussion here and I wanted to thank you for your spend time.

no problem.

I tried to edit the script and I deleted the “z = own.worldLinearVelocity.z” and replace it with “z = 0.0” and that worked for the slope in some cases, but know the player can’t jump.

Is there any easy way to fix it?

Hehe needed to say you are asking for it, the fix is the option that i have removed in v0.9 :stuck_out_tongue: so grab v1.0. but then you bounce again with high substeps. Solution fake slopes with a plane as detection, so when you hit the plane the anti slope sliding kicks in else it stays off.


(Cotaks) #16

Added a new improved version V2.

Have fun with it.