The marvelous task of using variables for ray-casting. Is it possible?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello!

    I tried my best to search the forum and internet but could not find an answer to this. So maybe you can help or have any advice :)

    Is there a way to use variables to use as input for a "ray-cast" to detect hitboxes?

    Let me elaborate on this one. I think its quickest to give a pseudo-code example.

    Global Variables:



    On any touch > set OldTouchX = TouchX

    > set OldTouchY = TouchY

    // This will save the "old touch position" after you are not in touch anymore. This way I can do the following:

    On any touch release && OldTouchX is between Button.X-(Button.Width/2) and Button.X+(Button.Width/2) && OldTouchY is between Button.Y-(Button.Height/2) and Button.Y+(Button.Height/2)

    // This way I can use a touches "end" rather than "tap" or "is touching" object to trigger events. This is a great behavior I couldn't find another way to accomplish.

    The Problem

    This works perfectly for rectangular elements! But is there a way to use variables to see if e.g. OldTouchX and OldTouchY are hitting an elements hitbox, rather than using "between two values"??

    This way you could use this "detect if object has been touched on touch end" to detect circular or even free defined hitboxes.

    Maybe also check out this other entry where we actually came up with this solution to solve the original problem of how to detect if an "object had been touched on touch end"


    Any thoughts or help on this one?

    Thank you <3 :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I have no idea why you need all this and why you have "ray-casting" in the subject. But the easiest way to check if a point is inside the object's hit box is to use "System Pick by overlapping point" event.

    So on touch end you can pick Button by overlapping (Touch.x, Touch.y) and that's it. You can also check if Button is overlapping (OldTouchX, OldTouchY).

    I believe "Is touching object" condition also uses object's collision polygon.

  • Thanks dop2000 for your reply :)

    "System Pick by overlapping point" is completely new to me; never heard of it. Can't wait to check it out, since it sounds like it is exactly doing what I need!

    This will save be the whole "is between values"-checking.

    But it wont save me from "OldTouchX" etc. because "Is touching object" does not work with "on touch end" because the touch already ended when the "is touching object" is checking for Touch.x and Touch.y.

    I run and check out the "System Pick by overlapping point" now now :P

    Thank a lot!!!

  • No, when "On touch end" is triggered, the screen is still considered in touch. So you can still check for "Is touching object".

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