|
|||||||
![]() |
|
|
Thread Tools |
|
||||
|
Well, it seems the Preacher was right when he said, "There is nothing new under the sun." Apparently, NOR.J already made a script just like this some time ago... Oh well, it was new to me, and I'm sure you'll still find the tutorial very useful and informative.
Here's the .blend. http://www.blendenzo.com/Files/Demos/customCursor.blend The short and sweet "How-to": Version Info: Blend made with 2.42a. Compatible with v2.34 and later. Requirements: Basic knowledge of Blender GE interface and ability to "plug in" a pre-written Python script Helpful Knowledge: UV Mapping Step 1 - Setup Generally speaking, it is best to setup your custom cursor on an overlay scene (since it avoids potential problems related to camera movement). Begin by adding a new empty scene and naming it "CursorOverlay". Now add logic bricks in the main scene to intialize the overlay scene. I like to put this type of logic on the camera. Make sure you turn off "Positive Pulse Mode" on the Always sensor. Switch to the "CursorOverlay" scene and add a camera. In the Edit context of the buttons panel [F9], set the camera's "Clipping: Start" value to something larger. 15 should work. ![]() In camera view [Numpad 0], add a new plane (this will cause the plane to be facing the camera). Move the plane about 20 blender units away from the camera and resize it to look good. You'll probably want to add a nice custom cursor texture at this point. Crosshairs should be centered on the plane. If you are using a pointer type cursor, make sure the point is at the top left corner of the plane. Note: If you are using Blender Materials, there may be some strange lighting on the cursor. To fix this, assign a material to the cursor, set it to "Shadeless" and give it a texture layer mapped to UV. Assign your cursor image to the texture layer. Step 2 - Centering the Cursor (Pointer type cursors only. Crosshairs skip to step 3.) Enter edit mode [Tab] on the plane and select the top left vertex. Press [Shift-S] over the 3D viewport and select "Cursor to Selection" from the pop-up menu. ![]() Now return to object mode [Tab] and go to the Edit context of the buttons window [F9]. Click "Center Cursor". ![]() You should notice that the object center (represented by a pink dot) has moved to the upper left corner of the plane. ![]() Step 3 - The Script (Social's Modified Version) Copy this script and paste it into the Blender Text Editor (use [Ctrl+Shift+V] to paste from the system clipboard) or download it here. Name the script "customCursor.py" Code:
With the cursor selected, go to the Logic context of the buttons window [F4]. Add two sensors and one controller. Leave one of the sensors an "Always", but make the second one a "Mouse Over Any" and name it "MousePosi". Set the controller to "Python" and set the script to "customCursor.py". ![]() You will also need to add a property named "init" and set it to a value of 1. (This is the property used by the script to center the mouse on the game screen at startup.) ![]() Conclusion It's that simple. Press "P" and watch it work. You'll notice that the cursor follows the movement of the mouse precisely, regardless of window size or camera bounds. If necessary, resize your cursor to make it look good in game and your done. Enjoy, -blendenzo
............................................
Game Engine tutorials: blendenzo.com - 3DKernel - TutorialsForBlender3D - blending-online My Projects: Solomon's Treasure - Sokoban - Marble Labyrinth Last edited by blendenzo; 02-Mar-07 at 02:14. |
||||
|
#1
|
||||
|
|
|
||||
|
Very nicley done Blendenzo! Works perfect here. It's no nice and simple, and so effective!
Keep it up! -Chaser
............................................
Gameblender Resources: >> Mouselook System >> A* Pathfinding Demo |
||||
|
#2
|
|
||||
|
Awesome! it works very nicely. and it can be applied to any object,Cool!
|
||||
|
#3
|
|
||||
|
Simple code, and it works perfectly. Thanks for that Blendenzo.
|
||||
|
#4
|
|
|||
|
Could i add that there should be a track-to actuator or halo mode on the mouse incase the camera moves?
............................................
My favorite word: Duotrigintillion. Last edited by Littlebob; 13-Feb-07 at 19:43. |
|||
|
#5
|
|
||||
|
LittleBob: I'm writing a tut right now, and I had that same thought, only I would say just make the camera the parent of the cursor.
............................................
Game Engine tutorials: blendenzo.com - 3DKernel - TutorialsForBlender3D - blending-online My Projects: Solomon's Treasure - Sokoban - Marble Labyrinth |
||||
|
#6
|
|
||||
|
blendenzo, if potatoes rocked, I would say you rocked like a potato. Excellent work, much better than the lame joke I tried to pull a few words back. I will be using this one, you can bet on it...
............................................
"Boy meets girl, girl meets boy.......boy asks 'what to do next' on 3d artists forum." - M@dcow "I'm so tired of all my actions having consequences!" - T-rex, Dinosaur Comics Into The Titan | Sunrise: A Webcomic | Art ~ ENOUGH WITH THE ZOMBIES |
||||
|
#7
|
|
||||
|
Thank you so much! I can really use this for my RPG I'm making! Thank you!
............................................
http://www.vidyanow.net/ <-- The Latest and Greatest Game Website Around! |
||||
|
#8
|
|
||||
|
ARG! Why is it that everything I download from blendenzo is an incomplete file? Always has been for me and can never figure it out! It does this to other files from a lot of people. Oh well anyways, I did the tutorial and works great
![]() ~Marshal~
............................................
A WIP thread gets hundreds of replies, but a finished game...
|
||||
|
#9
|
|
||||
|
Marshal,
That's odd, but I don't think it's related to my server. I test most of my downloads to be sure they're complete before I post links to them. Anyway, I'm glad that you all find the tut /script/demo useful.
............................................
Game Engine tutorials: blendenzo.com - 3DKernel - TutorialsForBlender3D - blending-online My Projects: Solomon's Treasure - Sokoban - Marble Labyrinth |
||||
|
#10
|
|
||||
|
Yeah, it's very use full, but I found one problem. It might just be the way I did it but, whenever I press P the cursor always starts off in the upper left hand corner. It's a small problem, but do you know how to fix this?
............................................
A WIP thread gets hundreds of replies, but a finished game...
|
||||
|
#11
|
|
|||
|
Just a few things to add:
- If your camera is moving, don't parent the cursor object to it. getRaySource() returns the position in world space, parenting only adds an extra transform. A plane set to halo is the best option. - There's a slight delay when using a moving camera, the cursor will appear to "jump" a little but this isn't noticable when the cursor object is further from the camera. - The position is on the near clip plane, so rather than move the cursor really really close and small, you can put it on an overlay scene linked to a dummy object, and adjust the cameras "start" value. Obviously don't move it too far or you'll notice clipping errors with your scene. @Meat_Beater - Until you move the mouse, I assume the mouse sensor defaults to the windows origin, which is the upper left corner for OpenGL. Piran |
|||
|
#12
|
|
||||
|
YES! This is great! I was using a different "customCursors" script, but this beats that tar out of that one!! This will fit nicely into my RTS...I will be sure to mention your name! (Not that it's a ground-breaking production or anything
)~~Stu_Flowers
............................................
Old MGP (Monkey Game Project) Website: --HERE-- |
||||
|
#13
|
|
||||
|
Piraniac: Thanks for the tips. I'll update my tutorial to reflect those points. I didn't know that halo was faster than parenting. Does halo not use transforms?
............................................
Game Engine tutorials: blendenzo.com - 3DKernel - TutorialsForBlender3D - blending-online My Projects: Solomon's Treasure - Sokoban - Marble Labyrinth |
||||
|
#14
|
|
||||
|
I assume there's nothing stopping you using a model instead of a plane as a cursor?
(e.g. Modeling a pointer, hand, gun, tool, persimmon etc.) as long as the hot point is the object center right?
............................................
"It's a primitive culture; I'm just trying to blend-in!" - Inebriated Counsellor Troi "You're blended alright." - Commander Riker Star Trek - First Contact
|
||||
|
#15
|
|
||||
|
You would be correct in making that assumption. I would go with the persimmon, personally.
............................................
Game Engine tutorials: blendenzo.com - 3DKernel - TutorialsForBlender3D - blending-online My Projects: Solomon's Treasure - Sokoban - Marble Labyrinth |
||||
|
#16
|
|
||||
|
Anyone who's having problems downloading:
I'm mirroring it for you at my site. Click
............................................
"Boy meets girl, girl meets boy.......boy asks 'what to do next' on 3d artists forum." - M@dcow "I'm so tired of all my actions having consequences!" - T-rex, Dinosaur Comics Into The Titan | Sunrise: A Webcomic | Art ~ ENOUGH WITH THE ZOMBIES |
||||
|
#17
|
|
||||
|
Quote:
Then modify your code like this: Code:
Blendenzo> Do I even have to say anything anymore? It's awesome of course, like everything else you do. Actually, now that I think about it.....you never published anything mediocre really, it was always awesome stuff one way or the other. Kudos to you buddy, kudos.
............................................
My blog: "The Blend With No Name" Last edited by Social; 14-Feb-07 at 02:00. |
||||
|
#18
|
|
||||
|
Thanks Social, It obviously worked! Blendenzo yours still worked 100 % of the time
![]() Thanks guys ~Marshal~
............................................
A WIP thread gets hundreds of replies, but a finished game...
|
||||
|
#19
|
|
|||
|
Quote:
It's a cool demo though, thanks for sharing. Piran |
|||
|
#20
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|