MouseMove - FPS Mouselook & Movement Script

Just reported it:
http://projects.blender.org/tracker/index.php?func=detail&aid=34517&group_id=9&atid=498

It says that link is invalid :frowning:

Is it this one? http://projects.blender.org/tracker/?func=detail&atid=306&aid=34517&group_id=9

I will track it and nag about it being fixed :eyebrowlift2:

EDIT: it is already fixed rev 55011 :yes:

We can replace W.positive by bge.logic.keyboard.events[bge.events.WKEY]

From this form it can remove 8 sensors from movement.py and we will see most clearly the logic breaks. So this are the sensors that it will removed

W = cont.sensors["W"]
S = cont.sensors["S"]
A = cont.sensors["A"]
D = cont.sensors["D"]
C = cont.sensors["C"]
E = cont.sensors["E"]
Space = cont.sensors["Space"]
Shift = cont.sensors["Shift"]

What are you think?

Edit:
I remove the sensors a,s,d,w,e,c and still I not remove the space and shift sensor
FP_Template26xUpdate1.blend (165 KB)

Ah, just in time for 2.66a :smiley:

@p9ablo - Iā€™m not too sure what youā€™re asking about. Did you perhaps post in the wrong thread?

I want remove the maximum of logic bricks. I removed 6 sensor of keyboard and I believe that it could remove more.

before:

after

I need help with the script in blender version 2.63 (the version its made for) Here are my two problems:

  1. I cant move the characterā€¦ Itā€™s as simple as that, the WSAD keys donā€™t do anything (Neither do the other ones). But I think that this is related to my second problem.

  2. Ok so when i look left and right, It moves my whole body (my body is a block for the feet, block for the body, with a head, with a camera, with a gun.) My body is all parented to the head and my gun to the camera and the camera to the head. So when I look left and right it moves everything, but when I look up and down, it only moves the camera left and right (not the whole body) and the gun (Since the gun it parented to the body).

I know this is confusing, but Iā€™m having a friend look at it as we speak and I just canā€™t be to sure. Iā€™ll attach the .blend for people to though anyways.

Thanks for the help in advance everyone

Thanks for posting the .blend, first of all. Thatā€™s always really helpful.

There are a few problems. The first one is that the Camera and the Head object both have the mouselook script, and you only really need one object to have it. If you remove the sensors from the camera and put them on the head, then that will be good enough.

I did that, which introduced a second problem: The rotation got all messed up, and the head would only rotate left/right, but not up/down. So I took the whole player and rotated it 90 degrees on the Z axis (so the head points forward along the Y+ axis). Then I applied the rotation values on the head (Ctrl + A > Rotation). I also applied the rotation values on the Body and Leg Trigger objects with ctrl + a (important for the movement part).

The last problem with the movement is the order of how you parented objects, as well as setting the properties to get the movement system working. Regarding parenting, the mouselook-script-object (the Head) should be parented to the Dynamic object, which in your case, would be the Leg Trigger object, not the body. The body could be parented to the Leg Trigger object.

Regarding the properties: Add a Boolean property named ā€œDMOVEā€ to the Head object, and set it to True.

The rotation values on the objects are important, because the ā€œforwardā€ direction of the script is along the positive Y axis, opposed to the positive X axis. After you get that right, you can grab the root parent object (Leg Trigger) and rotate your player in what ever direction you want it to face and it will work fine.

I fixed the .blend so you can have a look at whatā€™s different. Apart from the above modifications I mentioned, I changed the Mouse movement sensor to Always (true pulse); I also added a Ray and Collision sensor to the Leg Trigger object, and connected them to the mouselook Script logic brick on the Head - so that the player would jump realistically (disconnect them if you donā€™t want this). I also added some Sun lamps so I could tell what was going on.

.blend
http://www.pasteall.org/blend/19945

Wow!! Thanks for your quick response and helping me with this! I didnā€™t really expect there to be that many problems but I guess I should have suspected that since this is my first actual project/FPS in blender:) Thanks a lot for all your help and posting the .blend so I could look and see how you fixed it.

Big update! See the changelog here:
http://riyuzakisan.weebly.com/mouselook-script.html#changelog

Iā€™ve renamed the script to ā€œMouseMoveā€, and this is version 2.7

The Mouselook and player movement systems are now all independent of each other. Also, there are new property hooks for customizing the script, and all old property hook names have been changed. So if you update to this version, check your property names (itā€™s worth it!)

Let me know if you have any suggestions, questions, or come across any bugs!
Thanks :smiley:

I canā€™t get dynamic movement to work at all. Could you make a DynamicDemo.blend please?

Ah, I forgot to include info about that in the Demo.blend.
Go up to the Scene selector and switch to the one called ā€œDynamicMoveā€. Thatā€™s the dynamic movement demo.

  • I lack a property: dm.strafe,

I would like to set a fast speed forward and backwards, but less strafing, could that be possible?

  • For moving in stairs, I set the collision to capsule, but the movement is a bit jerky, could there be a feature to move smoothly in stairs?

  • For moving in midair, you do not move as if you are on the ground, but you are accelerating, which makes it kind of useless, I would expect you to move as a percentage of the movement on the ground.

Otherwise, very good movement script!!!

Thanks for the suggestions

For strafing, do you mean being able to set a slower/custom speed for strafing (left/right) movement? That would be possible.

Stair movement is a bit tricky, but I believe I could add in that functionality into the script. Usually people will set up a flat plane to act as the collision mesh for stairs, but I know thereā€™s a method involving ray casting to adjust the playerā€™s position.

Iā€™m not too sure what you mean about moving mid-air. I added the midair property to define how much the directional controls would move the player while they were mid-air. Set to 1.0, the player would have full control over movement even though they were in the air (Megaman type movement, for example); and 0.0 would be no control. Could you clarify what you mean here?

Oh, I see. That isnā€™t supposed to be happening with the mid-air movement. Itā€™s just supposed to give control over movement in air as it does when youā€™re on the ground, but not with such rapid acceleration. For some reason, itā€™s going over the speed limit.

Iā€™ll check that out, as well as the stairs feature. Thanks for letting me know about this.

Edit:
I found the problem. It isnā€™t limiting the velocity in the ā€œin airā€ state at all! I think I did this to allow for fast speeds in air, like if the player gets launched out of a cannon for example. Iā€™ll work on fixing that, but for a quick-fix for now, you can add ā€œself.limitVelocity()ā€ to the code after line 653. It should look like this:


        ### Apply Movement ###
        self.applyMovement()
        self.limitVelocity()

Awesome!

And btw using ā€œSphereā€ as collision makes the bumps in stairs not to bad!

In reality you do step up and down in stairs, so I am quite happy! I would not use smooth walking in stairs if you implemented it, I prefer a sphere as collision! :yes:

hi, a related question. This is all done with python i understand. Can i import this into a game that is written in C+++?

Hmmā€¦ that does not seem to work, the script does not respond at all if I add that lineā€¦

Also, I have problems with the camera when I point 45 degrees up, I then see whats directly behind me, but I have not tested it on other scenes as of nowā€¦

Make sure youā€™re only adding the line ā€œself.limitVelocity()ā€ after the ā€œself.applyMovement()ā€ function thatā€™s already there. Also try checking the console for errors. If you get anything related to indentation, try opening the script in the Blender Text Editor and go to Format > Whitespaces > Tabs to Spaces. It could be a problem with whitespace indentation in Python, depending on what program youā€™re editing the script with.

Yes! It works when I edited the external file, I had imported the file to blender and maybe that screwed it up :wink:

And the viewangle is not a problem anymore after importing the objects from your file again :smiley:

Ah, I see. I used Notepad++ to write the script, and itā€™s currently set to use tabs for indentations, rather than spaces as the Blender Text Editor does, so that kind of confuses Python to receive a script with mixed tabs and spaces :confused:

You can still import the script and use it internally, just be sure to do the Whitespace: Tabs to Spaces function in the text editor before modifying the script :wink:

Glad it worked