First Person - Clickable Objects

I am a Blender n00b, I have worked with VRML to try to realize a Myst inspired puzzle/exploration type game, but it is just too limited in functionality and allowing the player to look around etc. So I am recreating it in Blender.

I am using the Walkthrough demo I found (I forget the URL), it is a first person camera apparatice(?sp) that allows the player to look around by pressing the left mouse button down and moving the mouse. When looking around, the mouse pointer is invisible, but returns when the left button is released.

I would like to start basic. Simply allowing the user to click on items (very original Myst style), eventually I will try pulling switches etc by click and moving the object.

How would / could I allow the user to click on objects within my game ‘world’? The distance does not matter, I was thinking, if the player is within a certain distance from the object it can be clicked. So if the camera is near enough, and the left mouse button is clicked while the pointer is over the object, it needs to be ‘clicked’. If this is possible, is the logic/script housed in the object itself? I do not want to have to manage this from within the camera’s mouse events if I don’t have to, because then I would have to know all of the existing objects - rather than requiring only the object to ‘know’ its own clickable functionality.

I hope that makes some sense.

I have not found any tutorials etc on this yet. Even if you could just point me in the right direction that would be great!

Thanks in advance!!!

  • invid

a mouse over and mouse left button sensor connected to an and controller

the collision flagged faces are the ones you can click on.

Wow! That is SO much simpler than I thought it would be!!

Thank you, works like a champ. Now to actually go in and learn to make it do whatever I need it to!!!

Thanks!!!

  • invid

ooh… a forum newbie… .welcome…

I have a demo about Myst-style games at my site. It’s not exactly what you’re asking here, but it may help. www.terragna.com/~plantperson/blender.html

This works great, except that if I am using the mouse to move the camera’s angle of view - it will fire if the mouse moves over it. - Is there a way this could act like more of a ‘mouse up’ - or click as opposed to just checking that the mouse button is pressed? I don’t see any mouse click options within the logic bricks, so I am guessing it may require some python?

If so, is there a code snippet I can use as a starting point?

  • Thanks!!!

Thanks for the Myst style demo.

I am not building a node style navigated game, however. In mentioning Myst, I have caused some confusion in that way. The similarities between Myst and my game are simply in the ‘content’ and ‘goal’ of the game -

I am building a game where you explore and wander through a ‘world’ (but in real time, not node by node), solving puzzles, mysteries etc. Ironically, I am not much of a game player, and Myst is the closest game I have played to what I have in mind, and my ideas have been inspired by MystIII and MystIV.

But I am sure that your demo will come in handy in some unforseen way, I have added it to my samples archives thanks again!!!

Well I am finally coming back to developing in Blender. I have tried to go in and create, simply a clickable object - like discussed above, the code I have is:


import GameLogic as gl

ctrl = gl.getCurrentController()
me = ctrl.getOwner()

mOver = ctrl.getSensor("MOver")
mClick = ctrl.getSensor("MClick")

if ( (mOver.isPositive()) & (mClick.isPositive()) ):
	target = gl.getCurrentScene().getObjectList()["OBtgERGongF"]
	#target being the object you want the current object to move towards
	#Instead of OBGuide put your object's name prefixed with "OB"

	mepos = me.getPosition()
	targetpos = target.getPosition()

	#get the distances!
	xdist = targetpos[0] - mepos[0]
	ydist = targetpos[1] - mepos[1]
	zdist = targetpos[2] - mepos[2]
	
	#now the way of blending the movement from the object's location to the target's is another thing... you might come up with a SMARTER way but...
	#just a silly test! ^_^
	
	newpos = [mepos[0]+xdist*0.1,mepos[1]+ydist*0.1,mepos[2]+zdist*0.1]
	me.setPosition(newpos)

The above is not giving me any errors, but it is also not moving the object. Any ideas on where I am going wrong? I am new to python, so I am not sure where to begin in debugging this. thanks!

Well, it looks like I have to go back to version 2.36 :confused: in order to get this to work. But I have another question, I am using empty ojbects to create ‘sub coordinate systems’, how can I get positions according to the parent empty position? Here is the modified code I am using. I just want to add to the specified object’s position (this code is a bit sloppy, I am experimenting still). The object I am moving has a parent object that is an empty, its parent is not located at the main coordinate system’s center.


import GameLogic as gl

ctrl = gl.getCurrentController()
me = gl.getCurrentScene().getObjectList()["OBGong"] #ctrl.getOwner()

mOver = ctrl.getSensor("MOver")
mClick = ctrl.getSensor("MClick")

if ( (mOver.isPositive()) & (mClick.isPositive()) ):
	target = gl.getCurrentScene().getObjectList()["OBtgERGongF"]
	#target being the object you want the current object to move towards
	#Instead of OBGuide put your object's name prefixed with "OB"

	mepos = me.getPosition()

	#get the distances!
	xdist = 1.91 #targetpos[0] - mepos[0]
	ydist = 0 #targetpos[1] - mepos[1]
	zdist = 0 #targetpos[2] - mepos[2]
	
	newpos = mepos[0] + xdist, mepos[1] + ydist, mepos[2] + zdist # [mepos[0]+xdist*0.1,mepos[1]+ydist*0.1,mepos[2]+zdist*0.1]
	me.setPosition(newpos)