Collision alignment with multiple actors
Hello, and thank you for a great forum. I have been searching for a solution, so if there is a thread on this already, my apologies, I did not find it. I would appreciate any assistance you can provide, thank you!
Like many, I have run into an issue with actor alignment after collision. However, I have lined myself up for a slightly different challenge. I am building a logic/maze game that involves rotating the scene and allowing the actors to drop (I currently do this with acceleration). The main actor collides with "maze" walls and stops, allowing the scene to be rotated again.
All actors are 32x32, including the walls. Invisible collision (smooth) actors will not always work because sometimes the scene contains single blocks in the middle of the scene. I have manually placed all of the scene pieces on a 32x32 grid layout and had success with a single actor moving around the board. The actor does not catch any edges.
However, when I add a second actor, and they fall on top of each other, the actor on top appears to "sink" 1-2 pixels into the bottom actor after falling and stay there. When I then rotate the scene, the actor is caught on the "walls" rather than falling (accelerating) like it did before. I am not using round collisions because the actor must fall straight down, and round collisions have proven to bounce sideways when catching an edge.
All moving actors have bounce set to 0, density set to 0. The walls have bounce set to 0, density set to 1.
I have considered moving objects by checking the next grid block for the existence of a wall and moving it to that grid square if no wall exists. However, this seems cumbersome and memory intensive, especially when I need to start checking for other moving actors in that spot and then seeing if that actor is going to move or not due to a wall... the code gets long and brute-force. I was hoping there may be a simpler physics, trick-the-physics, or lack of physics solution I am missing.
If the explanation is not clear, please ask me to explain it a different way. I will include a picture or two if the forum lets me. Thank you for any ideas, I know there are plenty of great ones out there!
Single Actor (after falling)
Expected Result
Two or more actors (after falling)
Caught on edge of wall (pixel overlap?)
Comments
You've explained the problem very clearly and the pictures help a great deal.
My guess was that the starting position of your actors might not be whole number values of X and Y or that your actors' density might not be high enough, but I tried a test and neither of these fixes helped. In my test, I dropped the white actor using accelerate and set it to collide with the stationary blue actor. The display text is showing self.Position.Y for the white actor. As you can see, it's not a whole number:
My solution would be to change the moving actor's position to whole numbers when it is at rest. This can be done by doing Change Attribute self.position.Y to (round(self.position.Y/30))*30. The same can be done with the X position. That assumes your actor and grid size is 30 pixels.
GS physics isn't really my area of expertise but I'm sure someone else will have an idea about how to get this fixed.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang: Thank you for the quick response. Great explanation. Sure enough, I made the assumption that if I started on a whole number and put my walls on whole numbers that the relationship would be maintained (shaking my head now...). When I tracked the X and Y values with display text they are all off once things start moving. Interestingly, the actors stop cold when they hit a wall (immovable) but continue to try and accelerate through other accelerated actors (ie - values continue to change if you had two white actors stacked above). I am guessing this is because the bottom actor is "moveable" as well and can be pushed into the wall slightly?
I tried your solution above briefly, and I think it may work (x AND y since I rotate the scene), but alas, I need to tinker a bit to get it working...I am limited by my experience with GameSalad, but I'll get it figured out, i'm stubborn that way. I need to stare at my board and the math for a bit
Other ideas are welcome, but I will give this a shot first and write back. Thanks again!
Ok, so I am having trouble getting the "round" function to work.
I used (round(self.postion.y/32))*32 from tatiang's example.
When the actor hits a wall in the y-axis, I am still getting values like 443.875, 411.8749, 379.875. These are consistent when I rotate the board, but they should be 444, 412 and 380. (I double-checked the wall coordinates and they are at those whole values). Any thoughts on why the y position values not rounding up/down?
I currently have the change attribute for self.position.y inside of a rule looking for collisions with the walls... should I put it somewhere else? I also tried a rule looking for self.motion.linearVelocity.y = 0 but that had a similar result (and it never stopped calculating). Thank you for any additional ideas, I will keep trying to get the rounding to fire correctly.
I found that I had to use Constrain Attribute instead. Try that.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Also, velocity=0 is virtually unattainable. You'll find that of you do a Display Text for that it also never really reaches 0. Better to do something like velocity<1 and try various values to see what triggers it.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang: Constrain Attribute and Velocity <1 did the trick! The actor movement is no longer smooth, but I can work on that. At least the position values are locking into whole numbers now so I have a new goal to work with. I'll keep messing with it and see if I can put it all together. Thank you for the assistance. I'll try to pay it back.
Glad to hear it helped!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User