I want to make something like easy weld tool in that game(transparent object snap to object).:eek:
Right now I can welding thing and use mouse over to make it snap but I don’t have any idea to make it perfect snap.
So can anyone suggest some way to do it.:yes:
middle mouse = change obj scale
e,q = change obj axis
w,a,s,d,c,x = camera control
left click = place obj
press 1 and left click to constraint
right click at mouse over to unconstraint
use the mouse.hitPosition af a Mouse(over any) sensor and round the positions. This is quite easy to do with python:
import bge
G = bge.logic
cont = G.getCurrentController()# isnt'it? i forgot using only modules....
sce = G.getCurrentScene()
own = cont.owner
mouse = cont.sensors['Mouse']
x,y,z = mouse.hitPosition
rx,ry,rz = round(x), round(y), round(z)
#or even:
rx = int(x)
This is depending on how your models are set, if your scale of the models is in a usable range, integers should fit.
Otherwise we need to know, how exact the rounding should be.
Have a look to here:
if x is 123.4567:
round(x) returns: 123.0
round(x,1) returns: 123.4
round(x,-1) returns: 120.0
round(x,-2) returns: 100.0
You see? :eek:
If you have the correct Positions, simply add your Object at this coordinates.
I would recommend using an Empty wich always follows the hitPosition, and round its Position.
use the mouse.hitPosition af a Mouse(over any) sensor and round the positions. This is quite easy to do with python:
x,y,z = mouse.hitPosition
rx,ry,rz = round(x), round(y), round(z)
I already do this but object has 6 face so how to know which face mouse are over.
So I want transparent object rotate to match face of object that I want it to snap.
This is my work so far it can snap but only one face if big cube is rotate or mouse is over other face of big cube small cube is not snap
i see.. this gonna be a comlicated task, if you really want to snap on rotated Objects.
Because the grid on x,y is matching to the coordinates its easy, otherwise you’ll will need to calculate the rotation to create a virtual “rotated grid” on wich you can snap. As you can see in the Video above, the underground plane is not rotating, and a guess they guys who programmed that know why its not---- ;- ) .
Of course it is possible, but would not know how to calculate…
Here is a small example of the problem you will run into:
The Cube is snapping to the World Coordinates and rotates itself to the underground.
The snapping will not work anymore…
One way i would try, is to create a grit of emptys on wich the cube get snapped instead of using world Coordinates. This can be a workaround, but shure better would be a mathematical correct way…
Good Luck with that!!
Maybe some people with fundamentet mathematical skills could help you further…
If underground plane is not rotating.
How to find mouse is over which face of underground plane?
Thank for your help this problem is really hard.:spin:
I have one solution but it so much mathematical.
is it the Problem, that the blocks stand diygonal some how?
You could maybe try to:
preset the angles of added object, replace it with obj.replaceMesh()
instead of applying rotation, simply set the Orientation based on the hitNormal (pseudo:)
if hitNormal[0] in range(valuesmin, valuemax):
obj.Orientation = preset_ori[0]
something like that—
What is the meaning of it? i mean should it place the Object exactly at displayed Position and Orientation?
I would probably go with some Empties.
Lets say, you have a base , where you want to put other Objects ontop.
If the base have coordinates and Orientation as default, it will be easy to calculate a needed values like snapping-to- grid, Orientation and so on.
If the base is turned and Orientation is not like ((0)(0)(0)) or so,
it gonna be very complicated to calculate.
Thats why i would recommend to place the Objects by calculating the position by default Orientations of the target Object.
And then parent it to the target.
Now, you can change the Orientation of the parent so all childs will have the same Orientation…
Just an idea!
I would probably even keep the edit-mode in default values, and if neccesary turn the Whole world, only to make shure it is not rotated incorrectly…
So this time my little setup for snap object in real time is finish thank you sevi and other as well.
I post file in first post for anyone who interest.