[solved] Mouse coordinates on an horizontal plan

Hi,

I would like to know how to obtain the collision point in World coordinates of the mouse cursor on a plane. I know how to obtain the projection of the point on an imaginary sphere around the camera with

camera.getScreenVect(*logic.mouse.position)

but now i want to have the same but an horizontal imaginary plane (so no raycast or hitpoint ?) . i want this to be used with a getVectTo so my character can go to the point indicated by the cursor.

@Monster @wkk @BluePrintRandom

So you want to access just one mouse_cursor axis, & not all 2 axis’s :grey_question:

are you serious or trolling again ?


I’ll give a try to this

https://docs.blender.org/api/2.79/mathutils.geometry.html?highlight=mathutils%20geometry%20intersect_line_plane#mathutils.geometry.intersect_line_plane


edit : works perfect


What you need to do is have a plane with collision. Add a mouse over sensor (or mouse over any with xray. your choice). Then take the hitPosition from that sensor in a script and there. you have the 3d mouse position.

it was the thing i wanted to avoid , that’s why i asked :wink: I don’t like the idea to create assets stuff. Above, the solution is given. Details for those interested.

    from mathutils import geometry

    vec = cam.getScreenVect(*logic.mouse.position)
    camPos = cam.worldPosition
    projectedPos = [0,0,0]
    z = 20      #  length of the line
    projectedPos[0] = camPos[0] - vec[0] * z
    projectedPos[1] = camPos[1] - vec[1] * z
    projectedPos[2] = camPos[2] - vec[2] * z

   ## 3th argument any point belonging to the imaginary plan, 4th argument : axis, the plan is facing.
    juju = geometry.intersect_line_plane(cam.worldPosition, projectedPos, [0,0,1], [0,0,1], False)

    cube.worldPosition.x = juju[0]
    cube.worldPosition.y = juju[1]
    cube.worldPosition.z = juju[2]  

vector math my dude. vector math.

projectedPos = camPos - (vec*z)

cube.worldPosition = geometry.intersect_line_plane()