I am not sure how to explain this… I need a script that allows an object to appear where I click. I have my mouse in game, and I have my object that I want to appear there. Now how do I make that work?
I am just taking a guess here and I have no idea what I am talking about,
I imagine that using a mouse script you would get an x,y position. So you are simply missing a z coordinate to translate a mouse click into a 3D position (assuming you are looking down and clicking). Perhaps if had something like an empty high above the ground, you could move that to the x,y position obtained from the camera script, fire a ray toward the ground, and then add your object at the hit location (the x, y was already set and you know should have the z). I have no idea if this can be done in logic bricks or not, but, since you need python for a mouse, I assume you aren’t afraid to use some python.
Again I really don’t know what I am talking about, just theorizing.
What? Do you just need a script that shows the object under the mouse?
No, like imagine that I have a simple script that allows my mouse to appear in gameplay. Then, I need a script that allows, in gameplay, an object to appear exactly where I click my mouse. Then when I move my mouse away, I need the object to stay there…
Ohhhh. So you need a show mouse script, and a script that will put an object somewhere?
Okay, for this script all you will need is:
- An always sensor with pulse mode OFF called init
- A mouse over any sensor named mouse
- A click sensor named click
#Import some important modules import GameLogic as GL cont = GL.getCurrentController() own = cont.owner mouseover = cont.sensors['mouse'] if mouseover.positive: if cont.sensors['click'].positive: hitob = mouseover.hitObject own.localPosition = mouseover.hitPosition if cont.sensors['init'].positive: import Rasterizer as r r.showMouse(1)
Thanks a million!! I am learning Python myself, but until I learn it…
hmmm… doesnt seem to work. Could you post an example .blend please?
Did you set it up properly? I will post a blend ASAP
EDIT: MouseExample.blend (133 KB)
Thanks For some reason it wasn’t working even though I thought that’s how I set it up, I will check it now…
All right, got it. Now how would I restrict it from going up walls? Restrict it to only floors?
You could do a property test:
#Import some important modules import GameLogic as GL cont = GL.getCurrentController() own = cont.owner mouseover = cont.sensors['mouse'] if mouseover.positive: if cont.sensors['click'].positive: hitob = mouseover.hitObject if hitob.has_key('click'): #<------------------Property Check. own.localPosition = mouseover.hitPosition if cont.sensors['init'].positive: import Rasterizer as r r.showMouse(1)
How would I set that up? I’m sorry I am probably annoying you, but I know nothing of Python…
Is it possible you could post a second blend? I could eventually figure it out, but it would take 4ever. Also, I got the first script to work, but when I click on the floor, the object goes underneath it instead of on top of it.
EDIT: So that I cannot even see it at all… Or maybe it is disappearing, because I programmed my character to walk towards it and he won’t…
Here you go: MouseExample.blend (138 KB)
And its okay. We all have to ask questions when we are learning. I commented the code so that you can see exactly what I am doing.