sidebar features
sidebar content

Go Back   Blender Artists Forums > Game Engine > Game Engine Resources

Reply
 
Thread Tools
blendenzo's Avatar
blendenzo blendenzo is offline
Moderator
 
Join Date: Apr 2006
Location: Michigan, USA
Posts: 2,193
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:
import Rasterizer as R cont = GameLogic.getCurrentController() own = cont.getOwner() mPosi = cont.getSensor("MousePosi") ### Start mouse position at center of game screen if own.init == 1: R.setMousePosition(R.getWindowWidth()/2, R.getWindowHeight()/2) own.init = 0 ### Move cursor to mouse position cursorPosi = mPosi.getRaySource() own.setPosition(cursorPosi)
Step 4 - Logic Bricks
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   Old 13-Feb-07, 18:08   
Reply With Quote


Chaser's Avatar
Chaser Chaser is offline
Member
 
Join Date: Dec 2004
Location: BC, Canada
Posts: 966
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   Old 13-Feb-07, 18:13   
Reply With Quote
tarkata14's Avatar
tarkata14 tarkata14 is offline
Member
 
Join Date: Oct 2006
Location: In a parellel Universe...o_O O_o
Posts: 729
Awesome! it works very nicely. and it can be applied to any object,Cool!
#3   Old 13-Feb-07, 18:22   
Reply With Quote
Nigholith's Avatar
Nigholith Nigholith is offline
Member
 
Join Date: Dec 2006
Posts: 262
Simple code, and it works perfectly. Thanks for that Blendenzo.
#4   Old 13-Feb-07, 18:24   
Reply With Quote
Littlebob Littlebob is offline
Member
 
Join Date: Apr 2006
Posts: 386
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   Old 13-Feb-07, 19:41   
Reply With Quote
blendenzo's Avatar
blendenzo blendenzo is offline
Moderator
 
Join Date: Apr 2006
Location: Michigan, USA
Posts: 2,193
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   Old 13-Feb-07, 19:43   
Reply With Quote
PlantPerson's Avatar
PlantPerson PlantPerson is offline
Moderator
 
Join Date: May 2002
Location: Milky Way Galaxy
Posts: 5,051
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   Old 13-Feb-07, 21:25   
Reply With Quote
blender_rox's Avatar
blender_rox blender_rox is offline
Member
 
Join Date: Dec 2004
Location: The USA (Florida).
Posts: 743
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   Old 13-Feb-07, 21:54   
Reply With Quote
Meat_Beater's Avatar
Meat_Beater Meat_Beater is offline
Member
 
Join Date: Aug 2006
Posts: 245
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   Old 13-Feb-07, 22:12   
Reply With Quote
blendenzo's Avatar
blendenzo blendenzo is offline
Moderator
 
Join Date: Apr 2006
Location: Michigan, USA
Posts: 2,193
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   Old 13-Feb-07, 22:17   
Reply With Quote
Meat_Beater's Avatar
Meat_Beater Meat_Beater is offline
Member
 
Join Date: Aug 2006
Posts: 245
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   Old 13-Feb-07, 22:28   
Reply With Quote
Piraniac Piraniac is offline
Member
 
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 237
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   Old 13-Feb-07, 22:41   
Reply With Quote
Stu_Flowers's Avatar
Stu_Flowers Stu_Flowers is offline
Member
 
Join Date: Dec 2006
Location: Oregon
Posts: 524
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   Old 13-Feb-07, 22:48   
Reply With Quote
blendenzo's Avatar
blendenzo blendenzo is offline
Moderator
 
Join Date: Apr 2006
Location: Michigan, USA
Posts: 2,193
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   Old 13-Feb-07, 23:03   
Reply With Quote
Ammusionist's Avatar
Ammusionist Ammusionist is offline
Member
 
Join Date: Dec 2003
Location: City of Churches, Oz
Posts: 1,714
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   Old 13-Feb-07, 23:19   
Reply With Quote
blendenzo's Avatar
blendenzo blendenzo is offline
Moderator
 
Join Date: Apr 2006
Location: Michigan, USA
Posts: 2,193
Quote:
Originally Posted by Ammusionist View Post
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?
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   Old 14-Feb-07, 00:40   
Reply With Quote
PlantPerson's Avatar
PlantPerson PlantPerson is offline
Moderator
 
Join Date: May 2002
Location: Milky Way Galaxy
Posts: 5,051
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   Old 14-Feb-07, 01:46   
Reply With Quote
Social's Avatar
Social Social is offline
Member
 
Join Date: Nov 2005
Location: New Jersey, USA
Posts: 3,267
Quote:
Originally Posted by Meat_Beater View Post
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?
Add an integer prop to your cursor plane named "init" (no quotes), and set it to 1.

Then modify your code like this:

Code:
import Rasterizer as R cont = GameLogic.getCurrentController() own = cont.getOwner() mPosi = cont.getSensor("MousePosi") if own.init == 1: R.setMousePosition(R.getWindowWidth()/2, R.getWindowHeight()/2) own.init = 0 cursorPosi = mPosi.getRaySource() own.setPosition(cursorPosi)
Yea, I don't like the cursor coming out of nowhere like that either. Hope this is what you are looking for.

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   Old 14-Feb-07, 01:52   
Reply With Quote
Meat_Beater's Avatar
Meat_Beater Meat_Beater is offline
Member
 
Join Date: Aug 2006
Posts: 245
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   Old 14-Feb-07, 02:42   
Reply With Quote
Piraniac Piraniac is offline
Member
 
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 237
Quote:
Does halo not use transforms?
Everythings got a transform somewhere, the problem with parenting is the cursor inherits it's parents transformation as well as being set directly by your script - resulting in wierdness. Really all you want from the parent is an orientation, hence you can use halo to aim at the camera while your script deals with the position.

It's a cool demo though, thanks for sharing.

Piran
#20   Old 14-Feb-07, 09:35   
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 17:28.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Blender Headlines
Featured Artwork
Short animation: Barrel by Phlopper
Woolly mammoth by sebastian_k
Photorealistic classic furniture by eMirage
Social BlenderArtists