I have a C# Class object called "Slot" that basically contains a MaxVector3 and MinVector3. All other objects that inherit this "Slot" object are constrained to motion along a line connecting these two Vector3 objects.
When a collision with one of the endpoints of the "Slot" object happens, I want to effectively reverse the linearVelocity and linearMomentum so that the item will reverse back down the Slot in the opposite direction.
I have created two C# methods to accomplish this, but neither of them is able to override the Entity.linearVelocity value (even if I set Entity.linearVelocity = Vector3.Zero). No clue why I can't override these values with their negative equivalents?
I think what you might be encountering is the buffered nature of the linearVelocity field. Most of the entity properties that lack an 'internal' prefix (linearVelocity as opposed to internalLinearVelocity) are buffered for thread safety when the entity belongs to a space. Properties which are buffered say so in their intellisense comments.
Basically, writes to a buffered field while the entity is owned by a space are accumulated and finalized at the beginning of the next frame. You won't be able to immediately see the change.
Just setting it should work. For buffered fields, it'll take a frame to take effect. For a field like internalLinearVelocity, it will be instant. If you're not accessing it asynchronously, you can use internalLinearVelocity safely.
Like you have in the code sample, just doing something like:
Still not getting anywhere. I'm even getting some weird behavior where linearVelocity might be (-2000,0,0) but internalLinearVelocity might be (2000,0,0) at the same time. My Entity simply vibrates within a very small (maybe .5f units) space back and forth when it reaches the end of my "Slot" obj.
Here is a .zip with screenshots of my debugger as I step through values line-by-line. (It includes 10 separate screenshots for 2 consecutive passes through Update() method so all variables and values can be seen)
The different values for linearVelocity and internalLinearVelocity can be explained by the fact that one is buffered, and the other is not. Internal linear velocity will show you the current, unbuffered linear velocity. linearVelocity will show you the linear velocity as of the last read buffer update.
If you're still using the same code as above, the reason your object gets stuck at the end of the slot is that you never go below a magnitude of 0.5 on your velocity once it is reached. It goes negative, but it doesn't decrease in magnitude. Every single method call afterwards, the velocity will flip.