I have created a train system in which players who step in it are moved by the offset of the train when it is travelling. I got that out of the way but I stumbled upon a situation I must understand before I can continue with my game. I understand what inverse does and I understand what ToObjectSpace does.
Essentially:
b:Inverse() * a is the same thing as b:ToObjectSpace(a)
b:Inverse() * a is equal to a * b:Inverse()
Before I state my problem I will provide context of the train. The train is moving using tween service being done on the server and when a player activates a door prompt they fire a train event in the client which starts the loop that offsets the player to any of the trains movement until they leave or die.
If what im saying in (2) is accurate then why do the values print two different things in the output when train is moving via tweening which is being done on the server? (a * b:Inverse() provides the accurate data that actually offsets the player to the train movements, and if you switch the values the player slides of the train meaning the value isnt accurate)
Also if what I am saying in (1) is accurate why is b:ToObjectSpace(a) not offsetting to the movement of the train like a * b:Inverse() does. As I stated a * b:Inverse() is accurately offsetting the player to the train movement but if a * b:Inverse() == b:ToObjectSpace(a), b:ToObjectSpace(a) should also work but it doesn’t.
I have tried to reason this problem out on a different place.
But as you can see they all produce the same value like I thought it would:
So if its working perfectly fine on this different place, I am absolutely flabbergasted as to what the issue is here. Please if anyone could explain the sorcery I am witnessing here, I would greatly appreciate it.
This is incorrect
Matrix multiplication, unlike regular multiplication is NOT commutative
In certain cases it is (ie. for the transformations of two matrices with identity rotations), however this is not true for anything else
The logical error in your test case at the bottom is that they both have a rotation of 0,0,0 (the identity rotation), so its the “same” in that very specific scenario
HOWEVER, it is not true in any other circumstance
b:Inverse()*a is the proper way to do object space
Ok that definitely makes more sense now but could you please explain to me the proper way to apply offset to the character using object space and its respective inverse() version?. The only way I have gotten the players root part to offset accurately to the train is what you see in “local offset”
I did this exact thing a couple hours ago and it kept sliding off (not property offsetting to the platform of the train), but it must be some kind of mistake in my part. I will take everything you have said and edit my code in the mourning. Thanks very much, ill be sure to accept your answer if it works.
When I took everything you said into account, it wasn’t offsetting to the trains movement while alloying the player to move:
It seems like its using the players character orientation and adding a cframe to it causing it to slide off depending on where your looking. When I did it with the inverse function last like in the original code, everything worked. But as you mentioned that isnt the proper way to do inverse and tobjectspace.
I’m lost as to what the issue is, it could be a multitude of things but I have no clue what im doing wrong and why I can’t get ToObjectSpace to work at all.
Ok it works now for sure, it offsets correctly like before but I still don’t understand why Tobjectspace and inverse arent working like intended. Also what does “+=” mean, I have never seen that before and im not sure why its working.
Also the toobjectspace would work but its just more work than is necessary for this and isnt the most suitable situation for this
Youre trying to take an offset local to the train and apply it to something that isnt the train, and it just creates a ton of confusion when you could just use a global offset and itd work fine
oh so im assuming because the orientation for the train and the player won’t always be the same, it creates a problem with how offsetting works using cframe?
Yes, its just a bit wonky to try and use 3 different local spaces when its really more intuitive to just use global space, because the train and character are looking in completely different directions and it just creates unnecessary problems in short