GMS 2 (solved) Spine Collisions not working as expected (images and videos)

maranpis

Member
Hello guys:

I'm trying to make the enemy hit the player with the sword:




But it doesn't work well.

As you can see I set the bounding boxes in Spine:

Player



Enemy attacking




And the player and the enemy collisions are set to precise:

Player

Enemy


This is the simple code in the Enemy object:




So what Am I doing wrong?

Maybe the animation is too fast? or maybe i'm missing some Spine code?

Is there any other better solution? Like if animation is between frame number 20 and frame number 30 the player got hit? or maybe using GMS 2 collisions but what can i do with sword?

Thanks for your help in advance :)
 

Neptune

Member
I dont know anything about the spine portion, but if you did want to use GML, you could just create a little sprite that represents the sword collision mask, and have it track along the blade's path when the enemy attacks. And if it touches the player during that time -- it deals damage

Itd be a little tedious... Trial and error to get it to line up, but it works
 

maranpis

Member
I dont know anything about the spine portion, but if you did want to use GML, you could just create a little sprite that represents the sword collision mask, and have it track along the blade's path when the enemy attacks. And if it touches the player during that time -- it deals damage

Itd be a little tedious... Trial and error to get it to line up, but it works
thanks Vether, it's good idea but i don't know how to code that to follow the bone of the sword :eek: I need to practice more :(
 

jo-thijs

Member
Hello guys:

I'm trying to make the enemy hit the player with the sword:




But it doesn't work well.

As you can see I set the bounding boxes in Spine:

Player



Enemy attacking




And the player and the enemy collisions are set to precise:

Player

Enemy


This is the simple code in the Enemy object:




So what Am I doing wrong?

Maybe the animation is too fast? or maybe i'm missing some Spine code?

Is there any other better solution? Like if animation is between frame number 20 and frame number 30 the player got hit? or maybe using GMS 2 collisions but what can i do with sword?

Thanks for your help in advance :)
I don't have experience with spines in GameMaker either, but I can give some suggestions.

Looking at your video, it kinda looks like the collision mask of the enemy never gets updated from its initial pose in spr_enemy.
Using skeleton_collision_draw_set(true), you can make GameMaker visualise where the collision masks are and verify if they ever get updated.
In the screenshot of your code, it is also clear that you use a draw event, which might have something to do with the problem, so can you post the draw event?

I dont know anything about the spine portion, but if you did want to use GML, you could just create a little sprite that represents the sword collision mask, and have it track along the blade's path when the enemy attacks. And if it touches the player during that time -- it deals damage

Itd be a little tedious... Trial and error to get it to line up, but it works
thanks Vether, it's good idea but i don't know how to code that to follow the bone of the sword :eek: I need to practice more :(
If you ever want to have separate collision checks for the enemy and their weapon, you'll have to do that though.

For a little bit, I thought skeleton attachements might ave helped in this situation, but it doesn't look like they cause separate collision checks.

As to how to apply Vether's suggestion:
Use skeleton_bone_data_get to get the (x,y)-coordinates as well as the angle of the hand of the enemy.
In the create event of the enemy object, they create a weapon object and store their id in a variable.
In the end step event (or just after updating the position of the enemy), the enemy object resets
the (x,y)-coordinates as well as the image_angle of their weapon to the data retrieved from the bone.
In the destroy event of the enemy, destroy their weapon.
When the enemy creates their weapon, you can also store the enemy's instance id in some variable in their weapon.
You can then in the collision event of the weapon use a with-statement on that variable to make the enemy react in some way to the collision.
 

obscene

Member
I use Spine quite a bit but don't really do any masks work like this, but I do know for certain that s mask in spine cannot be animated. Whatever the mask is in the setup is what GM will recognize.

The simplest fix would be to just create an invisible object for a few frames, or you something like collision_rectangle() to check in front of a player. You could also separate the sword into its own object but you need to learn about getting bone data on-the-fly.
 
Last edited:

maranpis

Member
Ok guys so finally I have found a solution: (Thanks to all of you guys specially to jo-thijs and rIKmAN that help me in to this process)

I want to say that this solution works, maybe there are better ones using the bounding boxes in Spine but I didn't find anything that works as well as this solution at the moment, were are going step by step:

1. What do we want to do? As you can see(first post) we have an enemy and the player. The enemy has a sword and the enemy attacks the player and hurts him. So we need to create a bounding box in GMS2 that follows the sword bone.
1.JPGTo the right you can see the sword bone​
Now we have create this in Spine we have to create a bounding box in our gms 2 project.
Create in GMS 2, one sprinte with the size of your bone and then create the objet in GMS2:
2.JPG
Now its' time to code. We want this bounding box to follow the bone sword coordinates(code made by jo-thijs) :

Add to the create event of o_enemy the following:

Code:
sword_data = ds_map_create();
// In this code we create the ds_map called sword_data


Then add this code to the end step event:

Code:
ds_map_clear(sword_data);
skeleton_bone_state_get("SWORD", sword_data);
// In this code we are taking the data of the SWORD bone and put in in to the ds map called sword_data that we created.

Finally add this to the draw event:
Code:
var sword_x = x + sword_data[?"worldX"];
var sword_y = y + sword_data[?"worldY"];
draw_circle_color(sword_x, sword_y, 8, c_green, c_green, false);
var sword_angle = -bone_data[?"worldAngleX"];
draw_line_color(sword_x, sword_y, sword_x + lengthdir_x(8, sword_angle), sword_y + lengthdir_y(8, sword_angle), c_black, c_black);

// In this code we are setting the sword x position ( enemy x+ spine sword bone x) and the same with the y (enemy y postion+ spine sword bone y position). And drawing a circle to see it in the game (not neccesary)
then we are creating a variable that will be the sword angle (because we are taking the angle from Spine)
You should see a green circle following the sword handle, along with a black line inside the circle pointing in the same direction as the sword.

In this way, you can retrieve the position and direction of the sword in the end step event.
You can then use this to perform your own collision checks, instead of relying on the spine system.
For example, you could add a new sprite to your project that is just the sword with its collision mask (not as spine).
You can then have an invisible object follow the sword in the end step event and perform collision checks with the new sword sprite as mask.
Let's call this invisible object o_sword_mask and give it the sword sprite as mask.

You can then do the following in o_enemy:
add this to the create event:
Code:
sword_mask = instance_create_depth(x, y, 0, o_sword_mask);
// in this code we create the sword_mask instance in the enemy object.

put this in the destroy event:
Code:
instance_destroy(sword_mask);
// in this code just guarantees that when the enemy instance gets destroyed, the sword_mask instance following them also gets destroyed.It probably currently won't be doing anything in your project if enemies can't die.

put this in the other user defined event 0:

Code:
// Player (other) collided with sword
game_restart();


and add this to the end of the end step event:
Code:
with sword_mask {
x = other.x + other.sword_data[?"worldX"];
y = other.y + other.sword_data[?"worldY"];
image_angle = -other.sword_data[?"worldAngleX"];
}

with o_player {
if place_meeting(x, y, other.sword_mask) {
with other {
event_user(0);
}
}
}

Hope it helps!

 
M

MadPropz101

Guest
Ok guys so finally I have found a solution: (Thanks to all of you guys specially to jo-thijs and rIKmAN that help me in to this process)

I want to say that this solution works, maybe there are better ones using the bounding boxes in Spine but I didn't find anything that works as well as this solution at the moment, were are going step by step:

1. What do we want to do? As you can see(first post) we have an enemy and the player. The enemy has a sword and the enemy attacks the player and hurts him. So we need to create a bounding box in GMS2 that follows the sword bone.
View attachment 19425To the right you can see the sword bone​
Now we have create this in Spine we have to create a bounding box in our gms 2 project.
Create in GMS 2, one sprinte with the size of your bone and then create the objet in GMS2:
View attachment 19426
Now its' time to code. We want this bounding box to follow the bone sword coordinates(code made by jo-thijs) :

Add to the create event of o_enemy the following:

Code:
sword_data = ds_map_create();
// In this code we create the ds_map called sword_data


Then add this code to the end step event:

Code:
ds_map_clear(sword_data);
skeleton_bone_state_get("SWORD", sword_data);
// In this code we are taking the data of the SWORD bone and put in in to the ds map called sword_data that we created.

Finally add this to the draw event:
Code:
var sword_x = x + sword_data[?"worldX"];
var sword_y = y + sword_data[?"worldY"];
draw_circle_color(sword_x, sword_y, 8, c_green, c_green, false);
var sword_angle = -bone_data[?"worldAngleX"];
draw_line_color(sword_x, sword_y, sword_x + lengthdir_x(8, sword_angle), sword_y + lengthdir_y(8, sword_angle), c_black, c_black);

// In this code we are setting the sword x position ( enemy x+ spine sword bone x) and the same with the y (enemy y postion+ spine sword bone y position). And drawing a circle to see it in the game (not neccesary)
then we are creating a variable that will be the sword angle (because we are taking the angle from Spine)
You should see a green circle following the sword handle, along with a black line inside the circle pointing in the same direction as the sword.

In this way, you can retrieve the position and direction of the sword in the end step event.
You can then use this to perform your own collision checks, instead of relying on the spine system.
For example, you could add a new sprite to your project that is just the sword with its collision mask (not as spine).
You can then have an invisible object follow the sword in the end step event and perform collision checks with the new sword sprite as mask.
Let's call this invisible object o_sword_mask and give it the sword sprite as mask.

You can then do the following in o_enemy:
add this to the create event:
Code:
sword_mask = instance_create_depth(x, y, 0, o_sword_mask);
// in this code we create the sword_mask instance in the enemy object.

put this in the destroy event:
Code:
instance_destroy(sword_mask);
// in this code just guarantees that when the enemy instance gets destroyed, the sword_mask instance following them also gets destroyed.It probably currently won't be doing anything in your project if enemies can't die.

put this in the other user defined event 0:

Code:
// Player (other) collided with sword
game_restart();


and add this to the end of the end step event:
Code:
with sword_mask {
x = other.x + other.sword_data[?"worldX"];
y = other.y + other.sword_data[?"worldY"];
image_angle = -other.sword_data[?"worldAngleX"];
}

with o_player {
if place_meeting(x, y, other.sword_mask) {
with other {
event_user(0);
}
}
}

Hope it helps!

Hey, i came here after you replied to my thread, i tried your solution and it does work, thank you so much! However i'm really confused as to why getting the map data from the End Step Event works, and it doesn't work in Animation Update Event? I was using the manuals that YoYo Games themselves provided but for some strange reason it doesn't work...i keep having to come up with ghetto solutions to make Spine viable :(.
 

maranpis

Member
Hey, i came here after you replied to my thread, i tried your solution and it does work, thank you so much! However i'm really confused as to why getting the map data from the End Step Event works, and it doesn't work in Animation Update Event? I was using the manuals that YoYo Games themselves provided but for some strange reason it doesn't work...i keep having to come up with ghetto solutions to make Spine viable :(.
Hello MadPropz101:

I totally understand your situation because I'm also having problems. It's very challenging to use Spine in GMS2 (more than it should) but it's possible.

At the moment my knowledge is limited with the spine's integration in gms2 maybe somebody can help you out.
 

rIKmAN

Member
I'm confused as to why you guys are using a sprite for a collision mask instead of creating a bounding box in Spine and using that?
Has something broken with Spine collisions in the last update that I am unaware of?

@MadPropz101
In your other thread you get the bone data in the Animation End event and try to use it directly: x = bone_data[? "worldX"]
If you look at the code above from @maranpis you can see it is added to the existing x/y value: x = x + bone_data[? worldX]

This is correct and you should be getting this bone data in the Animation Update event, that is what this event is for.

When debugging, as well as using show_debug_message() do a draw_circle at the bones location so it's easy to see whether it is correct or not - I think once you start adding the bones worldX/worldY to the existing x/y value rather than using it directly you will find things work as they should.

If you have any problems, feel free to PM me and I'll be happy to try and help.

Lastly @maranpis: Take a look at using [ CODE ] tags when posting code, it will make things easier to read and be formatted correctly. :)
 

jo-thijs

Member
I'm confused as to why you guys are using a sprite for a collision mask instead of creating a bounding box in Spine and using that?
Has something broken with Spine collisions in the last update that I am unaware of?
Looks like it.
The collision boxes work as expected when I tested them in GM:S 1.4.
However, the same project in GM:S 2 behaved differently for maranpis (I can't use spine animations in GM:S 2, because I'm still on the demo version).
The bounding boxes stayed "stationary" as though the animation always remained on frame 0.

This is correct and you should be getting this bone data in the Animation Update event, that is what this event is for.
I didn't know about those events (I mean the "animation update" and the "animation event" events) before.
Those are handy!
However, I just performed some tests on the "animation event" event and I can't seem to ever trigger it.
Do you have any idea how to trigger this event?
 

rIKmAN

Member
Looks like it.
The collision boxes work as expected when I tested them in GM:S 1.4.
However, the same project in GM:S 2 behaved differently for maranpis (I can't use spine animations in GM:S 2, because I'm still on the demo version).
The bounding boxes stayed "stationary" as though the animation always remained on frame 0.
That sounds like the wrong function was being used to get the bone data.
There are 2 sets of functions - one which gets/sets the bone data for the setup pose, and one which gets/sets the bone data for the current pose within whatever animation is playing..

It sounds like the function to get the setup pose data was used (skeleton_bone_data_get) and so would only ever return frame 0 - the default pose.
To get the current pose of a skeleton in the current animation you would need to use skeleton_bone_state_get().
I didn't know about those events (I mean the "animation update" and the "animation event" events) before.
Those are handy!
However, I just performed some tests on the "animation event" event and I can't seem to ever trigger it.
Do you have any idea how to trigger this event?
You don't manually trigger the Animation Update event, think of it as being like the Step Event or Draw Event that is triggered every frame automatically but is specifically for getting and setting bone data on Spine skeletons. It allows you to read the current bone data, change it and set it using some of the skeleton_* functions.

Take a look at the following functions in the manual for information on the bone get/set functions and how access the bone data from the skeleton.

skeleton_bone_data_get - this is for the default / setup pose only (ie. frame 0)
skeleton_bone_data_set - this is for the default / setup pose only (ie. frame 0)
skeleton_bone_state_get - this is for the current pose (ie. within the current animation)
skeleton_bone_state_set - this is for the current pose (ie. within the current animation)
 

jo-thijs

Member
That sounds like the wrong function was being used to get the bone data.
There are 2 sets of functions - one which gets/sets the bone data for the setup pose, and one which gets/sets the bone data for the current pose within whatever animation is playing..

It sounds like the function to get the setup pose data was used (skeleton_bone_data_get) and so would only ever return frame 0 - the default pose.
To get the current pose of a skeleton in the current animation you would need to use skeleton_bone_state_get().
I'm aware of this by now.
I just forgot to mention my mistake on this thread.

However, that's not what I was talking about.
When I tested spine animations in GM:S 1.4, the bounding boxes worked dynamically, as you said they would, so no special functions or designs were necessary.
In GM:S 2, the same project apparently didn't work anymore.

You don't manually trigger the Animation Update event, think of it as being like the Step Event or Draw Event that is triggered every frame automatically but is specifically for getting and setting bone data on Spine skeletons. It allows you to read the current bone data, change it and set it using some of the skeleton_* functions.

Take a look at the following functions in the manual for information on the bone get/set functions and how access the bone data from the skeleton.

skeleton_bone_data_get - this is for the default / setup pose only (ie. frame 0)
skeleton_bone_data_set - this is for the default / setup pose only (ie. frame 0)
skeleton_bone_state_get - this is for the current pose (ie. within the current animation)
skeleton_bone_state_set - this is for the current pose (ie. within the current animation)
I understand the "animation update" event now,
I was asking about the "animation event" event that doesn't behave like I'd expect it to in GM:S 1.4.
 

rIKmAN

Member
I'm aware of this by now.
I just forgot to mention my mistake on this thread.

However, that's not what I was talking about.
When I tested spine animations in GM:S 1.4, the bounding boxes worked dynamically, as you said they would, so no special functions or designs were necessary.
In GM:S 2, the same project apparently didn't work anymore.
Not sure why it would work in 1.4 and not in 2.x, but I'm kinda flying blind here as I haven't tested this myself I'm basing it off what maranpis has said to me.
Could you give any more info on what didn't work?

It is possible that things have broken in GMS2 with regards to Spine collisions / bounding boxes in a recent update and nobody knows or has reported it.
I understand the "animation update" event now,
I was asking about the "animation event" event that doesn't behave like I'd expect it to in GM:S 1.4.
In what way?
Can you access the data in the event_data map?

Also what version of 1.4 are you using?
 

jo-thijs

Member
Not sure why it would work in 1.4 and not in 2.x, but I'm kinda flying blind here as I haven't tested this myself I'm basing it off what maranpis has said to me.
Could you give any more info on what didn't work?

It is possible that things have broken in GMS2 with regards to Spine collisions / bounding boxes in a recent update and nobody knows or has reported it.
Basically, maranpis shared their project with me through a PM.
I couldn't open it in GM:S 2, because I still run the demo vesion.
Instead, I reimplemented everything (almost) exactly the same in GM:S 1.4 and tested that.
Everything worked fine for me, unlike in the video.
I then asked maranpis to use debug features to draw where the collision box of the enemy is.
When I tested it in GM:S 1.4, it followed the sword.
Maranpis reported that the collision box didn't move along with the word and stayed at the same position as the first frame.
That makes it look like it is a bug in GM:S 2.

In what way?
Can you access the data in the event_data map?
The event never gets triggered in the first place, even though I have an object with a skeletal animation as sprite_index that is playing an animation and has no draw event (so uses the default draw event).
The manual states that the event should trigger (say, when a "Complete" animation event occurs), but it never does.
Here's a reference to all animation events by the way:
http://esotericsoftware.com/spine-unity-events

As a result, the event_data map never gets set up in the first place.

Also what version of 1.4 are you using?
GM:S v1.4.1804
 

rIKmAN

Member
That makes it look like it is a bug in GM:S 2.
This is possible, though I have just tested basic collisions and they work fine.
I also made a test project which I sent to maranpis via PM a few days ago which worked fine detecting the sword colliding with an enemy - I posted that in one of the threads they made.

I have a feeling it's user error in some way, but with you saying it worked in 1.4 and not in 2.x I'm not sure how I could verify that - all the tests I make seem to work as expected.
The event never gets triggered in the first place, even though I have an object with a skeletal animation as sprite_index that is playing an animation and has no draw event (so uses the default draw event).
The manual states that the event should trigger (say, when a "Complete" animation event occurs), but it never does.
Here's a reference to all animation events by the way:
http://esotericsoftware.com/spine-unity-events

As a result, the event_data map never gets set up in the first place.

GM:S v1.4.1804
The Animation Event will only trigger if you have setup event keyframes within your Spine animation.
As I said previously you can set event keyframes within the animation inside Spine and then these will fire (and fill the event_data map) at the exact moment they were set in the timelime.

If you don't setup any event keyframes in your animation, then the Animation Event will never fire or fill the event_data map because there are no events in the animation for it to read.
 

jo-thijs

Member
The Animation Event will only trigger if you have setup event keyframes within your Spine animation.
As I said previously you can set event keyframes within the animation inside Spine and then these will fire (and fill the event_data map) at the exact moment they were set in the timelime.

If you don't setup any event keyframes in your animation, then the Animation Event will never fire or fill the event_data map because there are no events in the animation for it to read.
Oh ok, got it!
Thank you!
 

rIKmAN

Member
Oh ok, got it!
Thank you!
I've just done a few quick tests using the latest version of GMS2 and Spine v3.4.02 and everything seems to be working.

I tested:
  • Spine skeleton with no bounding box colliding with normal sprite with a mask.
  • Spine skeleton with a bounding box colliding with a normal sprite with a mask.
  • Spine skeleton with a bounding box and animating colliding with a normal sprite with a mask.
  • Spine skeleton with bounding box colliding with Spine skeleton with bounding box.
  • Spine skeleton with bounding box and animating colliding with Spine skeleton with bounding box and animating.
Whilst not in-depth tests and only using basic skeletons and bounding boxes, all of the above appear to function as I would expect them to.
 

maranpis

Member
I've just done a few quick tests using the latest version of GMS2 and Spine v3.4.02 and everything seems to be working.
Hello rIKmAN:

I have been doing some testing with bounding boxes in Spine and in GMS 2,you are right setting bounding boxes in spine works.But now i have two questions:

1. As you can see in the video I'm not sure why I have these big bounding box just for the hand?

2. And why in both cases this delay between the collsion and the restart? I also tested with show_message and the delay is the same. :confused:


In spine it appears like this:
1.JPG
2.JPG














 

rIKmAN

Member
Hello rIKmAN:

I have been doing some testing with bounding boxes in Spine and in GMS 2,you are right setting bounding boxes in spine works.But now i have two questions:

1. As you can see in the video I'm not sure why I have these big bounding box just for the hand?

2. And why in both cases this delay between the collsion and the restart? I also tested with show_message and the delay is the same.
1. Try changing the collisions to precise in the sprite properties.

2. I'm not really sure what I'm looking at, or how you are drawing / updating the red thing that seems to be delayed? Is that the issue you are talking about, or something else?

Are you still manually drawing a sprite to use as a mask?
What exactly are you doing, what do you expect to happen, and what actually is happening?

As a side not and without trying to sound mean, looking at the layout of your code in the video I would really advise you take some time to format it properly to make it easier to read and follow as it's a mess.

Your indentations, spacing and braces look all over the place and can only serve to confuse you as you try to go through the logic of what is happening and trying to fix your issues.

Also while you are still learning about how Spine and the collisions etc work, I would suggest not trying to cram everything into your main project as you are just adding layers of complexity to the issue you are trying to solve, making it hard to find where the actual problem is.

Instead, make new projects using the same assets which you use to just test a single feature or set of functions (ie. sword collisions, animation mixing, bounding box detection) and then once you have that working you can add it to your main project confident that that isolated code works fine and if there is an issue that it isn't with that piece of code - because it's already been tested and proven to work fine.

Simplify as much as you can, especially when learning.
 
Last edited:

maranpis

Member
What exactly are you doing, what do you expect to happen, and what actually is happening?
When the sword touch the hand the player turns to red. (I well implmented that using the bounding boxes of GMS 2, tomorrow i'll try with setting the bounding boxes in Spine)


Simplify as much as you can, especially when learning.
Thanks for the advices I will apply to my project. At the moment I'm testing like crazy but I saved the project before messing around, your advice of isolating the new code is very good, thanks for that :)

1. Try changing the collisions to precise in the sprite properties.
I tried, but it keeps giving me this big box, this is something between spine and GMS2 i guess.:(

3.JPG
This huge bounding box just for the hand.

1.JPG

and these are the bounding boxes in spine one on the ground an the other a diamond on the hand.

Do you know what could be the reason for that?
 

rIKmAN

Member
I tried, but it keeps giving me this big box, this is something between spine and GMS2 i guess.:(

Do you know what could be the reason for that?
The large rectangle in your image isn't the bounding box for the hand, it is encompassing all of the attachments - the feet and the hand.
You can see it aligns with the bounding box on his feet in the bottom left, and the hand in the top right.

If you animate the skeleton that box will also grow and shrink to make sure it encompasses the attachments.
If you load up the project I sent you last week with the slime and sword, and uncomment the skeleton_collision_draw(true) line in the sword Create Event, you will see that the bounding box is drawn around the sword blade tightly, and that there is a larger rectangle which adapts it's size as the sword rotates to make sure it encompasses the whole sword.

Here's a gif to show what I mean:


See how the large box adapts it's size and shape - that's what is happening in your image where it's encompassing the hands and foot bounding boxes.

The function to draw the collision boxes more than likely uses skeleton_get_minmax() behind the scenes, check that link for details of what I have just described re: encompassing all the individual bounding boxes.

Honestly, I think you are trying to run before you can walk - as I said previously I'd advise making lots of different projects to test out different functions and features to get to learn how they work, then once you understand how everything works in isolation (collision, bounding boxes, accessing bone data etc) then you can put it all together in your main project with a much better understanding of what may be going wrong.

Also - again: clean up that code so it's easier to follow, the way you have it laid out at the moment is just going to make things a lot more difficult to follow, find bugs, and fix.
 
Last edited:
M

MadPropz101

Guest
I'm confused as to why you guys are using a sprite for a collision mask instead of creating a bounding box in Spine and using that?
Has something broken with Spine collisions in the last update that I am unaware of?

@MadPropz101
In your other thread you get the bone data in the Animation End event and try to use it directly: x = bone_data[? "worldX"]
If you look at the code above from @maranpis you can see it is added to the existing x/y value: x = x + bone_data[? worldX]

This is correct and you should be getting this bone data in the Animation Update event, that is what this event is for.

When debugging, as well as using show_debug_message() do a draw_circle at the bones location so it's easy to see whether it is correct or not - I think once you start adding the bones worldX/worldY to the existing x/y value rather than using it directly you will find things work as they should.

If you have any problems, feel free to PM me and I'll be happy to try and help.

Lastly @maranpis: Take a look at using [ CODE ] tags when posting code, it will make things easier to read and be formatted correctly. :)
Hey you're right, i didn't add up the x values, however i'm still not sure why it works like that. I thought worldX was the x position of the bone relative to the root, so as long as the root is moving the bone x should stay at the same distance from the root and move alongside it?
 

rIKmAN

Member
Hey you're right, i didn't add up the x values, however i'm still not sure why it works like that. I thought worldX was the x position of the bone relative to the root, so as long as the root is moving the bone x should stay at the same distance from the root and move alongside it?
It is a value relative to the root, so if the bone was directly to the left of the root by 100px it would have a value of x: -100 (relative to the root bone).
So wherever the root bone is, this bone will be at that position -100 on the x axis - which is why you need to add it to the root bone position.

If you use the value directly after you get it from the map, you are using the value -100 because it doesn't have any idea of the position of the root bone to offset from.

What you want to do is get the position of the root (for example 500, 500) and then add the relative value from the map: 500 + -100 = 400.
This is correct for our example where the bone is offset from the root by -100.

You can check the values from the map by either outputting them to the console or add a breakpoint and then inspect them in the debugger and step through to see them as they populate the map each frame.
 
M

MadPropz101

Guest
It is a value relative to the root, so if the bone was directly to the left of the root by 100px it would have a value of x: -100 (relative to the root bone).
So wherever the root bone is, this bone will be at that position -100 on the x axis - which is why you need to add it to the root bone position.

If you use the value directly after you get it from the map, you are using the value -100 because it doesn't have any idea of the position of the root bone to offset from.

What you want to do is get the position of the root (for example 500, 500) and then add the relative value from the map: 500 + -100 = 400.
This is correct for our example where the bone is offset from the root by -100.

You can check the values from the map by either outputting them to the console or add a breakpoint and then inspect them in the debugger and step through to see them as they populate the map each frame.
Oh i see, thanks for explaining.
 
Top