Anyone knows how to check the object hit object

  • #1, by genaticstudioFriday, 08. November 2019, 17:29 4 years ago
    Anyone knows how to check the  object  hit object.
    Is there a way to check?

    Thank you.

    Newbie

    20 Posts


  • #2, by afrlmeFriday, 08. November 2019, 19:03 4 years ago
    Hmm... are you talking about collision? You would need to use Lua script to do that as there's no alpha/mask solution built into the engine to detect overlapping objects.

    You wouldn't be able to do anything complicated with Lua script, only check if 2 circles or rectangles overlap one another, but even that isn't very simple to sort out as it requires loops & probably a fair amount of code.

    Could you explain in more detail exactly what it is that you are wanting to do please?

    Imperator

    7278 Posts

  • #3, by genaticstudioSaturday, 09. November 2019, 05:46 4 years ago
    Yes. I mean collision.
    Thank you for your advice.

    Ex. 
    if objectA collision objectB = true 
    {
    change condition [empty] = true OR false
    }

    Newbie

    20 Posts

  • #4, by afrlmeSaturday, 09. November 2019, 12:55 4 years ago
    Yeah, you would need to use Lua script to sort that out. I can't explain how to sort out checking if 2 shapes overlap each other off the top of my head, so you will have to do a bit of googling to find some examples of collision detection done with Lua, then you will have to edit the code to make it work in Visionaire.

    Quick note: the engine does have a built in function (via scripting) for checking if a point (x, y) is inside of the object area of a scene object, character, etc. but that only checks a single point.

    Imperator

    7278 Posts

  • #5, by pietro-eccherSaturday, 09. November 2019, 17:04 4 years ago
    I had a function to check this: assuming that you can provide x y coordinates and width and height for the two objects it should return true if they collide: (not tested though, it worked on other lua engines)
    --where x,y,w,h are relative to sprite1 and the others to sprite2 (rect based)
    local function collides(x,y,w,h,x2,y2,w2,h2)
    return not ((y+h y2+h2) or (x > x2+w2) or (x+w < x2))-- wrong because of some forum layout rule. 
    --See below for the correct one
    end
    


    P.s. I don't know why the forum breaks the code:
    the line should be like this one
    return not ((y+h < y2) or (y>y2+h2) or (x > x2+w2) or (x+w < x2))

    Newbie

    29 Posts

  • #6, by afrlmeSaturday, 09. November 2019, 17:47 4 years ago
    forum cms is buggy, when it does that I usually just click on on the edit post & then the save button & it seems to fix the post.

    yeah you can get the width & height of a static sprite - believe it's possible with animations too, but less simple. maybe a radius or rect would be better?

    Imperator

    7278 Posts

  • #7, by blanoWednesday, 15. January 2020, 10:49 4 years ago
    hello everyone,
    i write here instead open a similar thread..!
    i'd like to create a trap that if the player is in it, something happen
    i don't want to create complicated traps, just spike zones or closing walls!
    i suppose i've to use a collision-like system via lua.

    where to start? can you link some reference?

    Newbie

    68 Posts

  • #8, by joemidWednesday, 15. January 2020, 17:12 4 years ago
    What about an action area?  You can set up a polygon in the waysystem that reacts to player entry or exit.

    Newbie

    87 Posts

  • #9, by blanoWednesday, 15. January 2020, 21:01 4 years ago
    thank you joemind!
    yes would be perfect if the trap effect is static, but what if the spikes are hidden in certain moment and not in other? or the walls are open for awhile and then close?

    Newbie

    68 Posts

  • #10, by afrlmeWednesday, 15. January 2020, 23:46 4 years ago
    There's a Lua function Simon created a while back that let's you check if something is inside of a polygon/object area. if you create the walls as objects then moved them & used a loop you could listen out for when one of the objects overlaps the players position, or check if player is inside of a polygon when the 2 walls are x distance apart or something. I'm not going to go into details about how to solve it because you haven't gone into much detail about your plans for these traps or how they are supposed to work.

    Imperator

    7278 Posts