Ragdoll and physic with spine / skeletal animation

Discussion in 'Programming' started by Didjynn, Apr 28, 2019.

  1. Didjynn

    Didjynn Member

    Joined:
    Oct 8, 2016
    Posts:
    107
    Hello everybody,

    Did any of you already used a spine skeletal to make a ragdoll ? It would be perfect for what I'm trying to do since I could use my already animated characters and make them ragdolls when they die without much more work.

    Also, how to make it consider what the ground is? I saw tutorials about that but they are for gms 1.4 and to add a collision event doesn't seem to be enough in gms2.

    Thanks for your tips
     
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Joined:
    Apr 13, 2016
    Posts:
    6,903
    I can't help you with the Spine part (as I don't use Spine), but the colliion event in the GMS2 physics system works the exact same as in GMS1.4... so, if you have a physics enabled room and two physics enabled instances with their fixtures defined, then they should collide off each other as long as there is at least a comment in their collision events.
     
  3. Didjynn

    Didjynn Member

    Joined:
    Oct 8, 2016
    Posts:
    107
    Hello, thanks for your reply. I found the problem with the collision, I did not give it a collision group.

    I still haven't find yet how to use skeletal Spines to make ragdolls.

    I met another problem, I would like to make localized shooting : if I shoot the head, the head explode, if you shoot a shield, the shield take damages, etc.
    The problem is the objects are considered as one skeletal object so how to know if a collision occur on a particular bone / sprite of the object ?

    Also, I tried to make my character shoot projectiles but with the physic of the room I can't just give it a speed and a direction so I use physics_apply_impulse
    the exact formulation I use is physics_apply_impulse(lengthdir_x(x, dir), lengthdir_y(y, dir), lengthdir_x(vit, dir), lengthdir_y(vit, dir))
    But after a vit value of 10, the projectile just don't go faster and I would like it to be very fast. Is there something I missed here ?
     
  4. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,537
    If you want your skeleton to have multiple areas that can be hit, detected and damaged individually then you need to set up the bounding boxes inside Spine that correlate to each slot / body part you want to be able to detect. Then you need to use the skeleton functions to calculate the bounds of all of these every frames and detect collisions against those polygonal bounding boxes.

    I wrote an extension which allows individual slot colouring / alpha and (more relevent to you) individual slot detection which may be of use (at least you can try loading your skeleton into the free tool on the download page) and although the functionality has since been added to natively to GMS2 (not sure about the collison stuff, you'd have to check) if you are using 1.4 then it might help you out as detecting the collisions of a point on a slot is a single function call - all the hard work is done for you.

    For the ragdoll stuff, although I've never tried it myself the usual way of doing it would be to read the state of the Spine skeleton at the point you would want to turn it into a ragdoll, and use all the bone and slot data (position, angle etc) to recreate a physics skeleton using fixtures etc and then remove / hide the Spine skeleton and let the physics skeleton react according to the physics engine and flop all ove the place.

    You could do it the other way around and set the Spine skeleton to the same positions / angles as the physics skeleton, but either way you are going to be using 2 seperate setups - a Spine skeleton and a physics skeleton for the ragdoll - and I think the first method is much easier as it's just replacing the Spine skeleton with a physics rig that has the same starting values as the Spine skeleton so that the transition to ragdoll looks seamless.

    Somebody was doing this a (long?) while ago but I can't remember who it was.
    If you have a trawl through the forums or via Google you might come across the thread where they were asking / posting about it.
     
  5. Didjynn

    Didjynn Member

    Joined:
    Oct 8, 2016
    Posts:
    107
    Thanks for your answer.

    I had a lot of reading about all this today and I'm quite lost.

    [​IMG]

    I found this subject where you also replied :
    https://forum.yoyogames.com/index.p...-working-as-expected-images-and-videos.48954/
    It made me realize I'm not moving my object at all, only the coordinates of its bone. I don't know if it can be a problem but to make the object move might be a problem for the foot positions since it would move everything.

    I don't know how to use these bounding boxes and what options should be checked to make them work... should I just get it with skeleton_get_minmax() and then collision_rectangle() to know where was the collision ?

    [​IMG]
    Here for example I have a box for the head, the body, 2 for earch arm and leg. If I shoot on it I would like to be able to say if I touched the head ot an arm. But I also have this rectangle collision box that gms2 makes me create to not have a crash.
    The object have physic enabled, but it works on the object not on its bones.

    Which funtionnality are you talking about ?

    If I understand there is just no way to do it with Spine. You can't just transform automatically each bones in fixtures for example ?

    Also last question if I may, it's the first time I use the physic and I would like to shoot bullets at a character giving it a lot of speed to make the character fly away when hit. Maybe I should do bullets not using the physic at all but I hoped to get a good effect and spare myself a lot of coding with this but my bullets are slow whatever the "strength" (vit variable) I give to it.

    Code:
    vit = 100000000000
    physics_apply_impulse(lengthdir_x(x, dir), lengthdir_y(y, dir), lengthdir_x(vit, dir), lengthdir_y(vit, dir))
    
    It has 0 friction and I tried with 1 or 0 density, it doesn't change it.
    I tried with a "vit" variable of 5, it does the same than with 10000000
     
  6. Didjynn

    Didjynn Member

    Joined:
    Oct 8, 2016
    Posts:
    107
    Well after loosing 10 days on this I guess I'll just give up, I can't afford loosing more time.

    var xxl = ds_map_find_value(map_pied_d, "worldX")
    var yyl = ds_map_find_value(map_pied_d, "worldY")
    It seems like world coordinates aren't relative to the root anymore. I tried it and it is really giving me the world position and I don't need to add the x and y position of the object.

    I don't find how to get easily the world angle of a bone, it is relative with the previous bone making it really annoying to work on.

    skeleton_get_minmax creates a straight rectangle, so the shooting precision might be not precise enough.

    Also I don't explain myself how and why this code finds my mouse in the bounding box ONLY on the edges, not inside. I would like to know if I made a mistake somewhere in the "if" statement. The mask of the sprite is on "precise collision checking"
    Code:
    
      array = skeleton_get_bounds(1);
       for(i = 0; i < array[0]; i ++) {
           if ((mouse_x > array[2 + i] && mouse_x < array[4 + i]) or (mouse_x < array[2 + i] && mouse_x > array[4 + i])) && ((mouse_y > array[3 + i] && mouse_y < array[5 + i]) or (mouse_y < array[3 + i] && mouse_y > array[5 + i])) {
               show_debug_message("I'm in it's a miracle")
               candraw = true
               break;
           }
       }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice