Anyone knows how to check the object hit object

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

    Thank you.

    Newbie

    3 Posts


  • #2, by afrlmeFriday, 08. November, 19:03 A week 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

    6624 Posts

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

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

    Newbie

    3 Posts

  • #4, by afrlmeSaturday, 09. November, 12:55 A week 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

    6624 Posts

  • #5, by pietro-eccherSaturday, 09. November, 17:04 A week 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
    1
    2
    3
    4
    5
    6


    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

    16 Posts

  • #6, by afrlmeSaturday, 09. November, 17:47 A week 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

    6624 Posts

Write post