How do I trigger an event when clicking on a 3d object?

0 favourites
  • 6 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Seems that the click event only fires when clicking the plane where the 3d object is on. Like looking straight down on top of the 3d object I can click but if I'm looking at it from the side I can't.

    I can't see to find how I can click any side of the 3d object with a camera looking from any angle to fire the event.


  • Use the line of sight behavior to cast a ray. On intersect, check the angle of the click with the hit distance and compare with the object height and z elevation.

  • Use the line of sight behavior to cast a ray. On intersect, check the angle of the click with the hit distance and compare with the object height and z elevation.

    This is where you lost me... Not sure where I'm seeing options for angle of click or hit distance.

  • The line of sight behavior has a hit distance expression.

    The angle of the mouse click to the target would depend on your camera and field of view. You'd probably have to account for the height of the camera as well. With the angle and distance, you can use tan(angle)*distance to get the height of where your click was at the point it intersects the base of the object.

    Getting the angle might be finicky, I haven't actually tried to see if it can accurately be done myself. There is no support for 3d collisions right now afaik, the underlying engine is still 2d after all.

  • I don't think it can work as there's no ability to set a Z axis for the line of sight behavior (Or pretty much any existing functions).

    I was messing around with basically firing a sprite from the camera to where the user clicks by means of the move to behavior and manually adjusting the z elevation of the sprite as it moved which can sort of work because collisions are detected. But ran into issues with regards to speed and the thing moving so fast it was going through the object being clicked on and not detected.

    So my solution thus far is instead of having the behavior move the sprit is to create a loop based on the distance from the camera to the click location and iterating through moving the sprite 1 px at a time and checking for collision.

    First test seemed to work but lots of tweaking is needed. But now I'm thinking "ok, so that could work for clicks but what about hovering?"

    The mechanics of using this just seem so horribly inefficient. I really think the correct solution here is for the devs to actually code this simple functionality into the game engine.

    Thanks for your suggestion though

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Sorry, I forgot to mention in regards to your solution I also don't believe it will work because there's too many other variables like the shape and obstructions. It might work ok if you've got a clear shot from the camera to the object and it's a box. But if it's a pyramid and/or it's partially obstructed from the camera and you click on it... Gonna be some crazy math to figure if it's actually being clicked on.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)