Controlling Velocity Interaction (Or controlling entities)
Posted: Wed Oct 29, 2014 1:44 pm
I'm having difficulty controlling the way entities interact with each other. I need to have entities in my game that move at constant velocities (such as the player and some enemies/npcs, dynamic or not) interact with each other, and some other (dynamic) entities (not moved by editing the velocities) with controllable behaviour (ie. one control would be limiting max velocity such as a clamp operation done every frame on linear velocity before running Update() on a physics space).
For example, if I were to have a dynamic box (no localtensor, so no rotation, represents a player character) with a mass of 1 unit constantly moving forward 1meter(s)/second to collide with another dynamic box (rotation enabled, represents an object that can be interacted with) that has a mass of 1 unit on a flat plane, the expected behaviour is that the object box is pushed along with the box.
This is sort of what happens, although it is not perfect because it seems the object box gets "snagged" by the triangle data's lines on a flat plane mesh I am using (happens whether it is a mobile mesh entity or a static mesh. The mesh is flat so there is are no problems with that, using a few box colliders for the floor is the same effect) for the floor and then strays from the direction it is being pushed in, sometimes a little violently, and may even be thrown in the air a little. I don't know if that is supposed to happen but for now it does not matter as much to me as everything else I will explain. So for the most part the behaviour is expected.
If I increase the mass (twice, thrice, etc.) of the box that represents the player the behaviour that is expected also happens for the most part (distance the object is expected to travel is somewhat inconsistent), that the object box is flinged ahead more as the mass of the player box increases.
Now, this is all well but I need to be able to create a different sort of behaviour. I need it so that no matter what velocities the player box may be traveling at, or even what mass it has, the player box should gently brush aside the object box instead of flinging it upon impact (because the velocity of the player character will be well above 1 meters/second there will be a lot of force applied even at similar mass relationships) and not lose it's own velocity (setting the object box's mass at a higher ratio than the player box yields the effect that I want for the object but not the player as the player now does not move at it's full velocity set every frame). The way I am currently moving the player box is by setting the linear velocity every frame (the change between desired velocity and current velocity is added to the current velocity every frame, works better than setting the velocity directly because gravity starts becoming an issue) and it works just fine for moving it so I would like to continue to be able to do this.
I think a good way to describe what I want is something that I have tried and seems to have the similar effect I want. That is, I used a kinematic box to represent a player, and used the character controller to represent the object. By setting the controller to ridiculous settings for traction, forces, glue, etc. I was able to have the fast moving kinematic box (just moves in a back and forth pattern, and it is kinematic because I don't want it to lose any velocity upon hitting objects) push the object gently along with it in it's path and not fling it across the scene (which is what happens without adjusting the settings). The issue is that I don't think I need a character controller for every physics object like that in the game, it would get ridiculous to have hundreds of controllers representing some debris objects, and I'd like to be able to use dynamic entities for the players/npcs so they can move each other as well (perhaps not in the exact same relationship as this though, but simialrly),
So is there a way I can achieve this sort of relationship with the "player" and "object" dynamic entities? In this particular case, to restrain the impact the player moving has into the object entities, ensure the player does not lose velocity upon impact, and keeping the relationships of other object entities amongst themselves the same. I feel like the answer might lie in the collision events that take place during the physics calculations ie. PairUpdating, but I really don't know how I would do it even with that. Also, this is only one step of the way for me as I mentioned earlier that I plan to have players/npcs interact with each other in a similar way (players colliding into enemies/npcs but not flinging them away because of mass/velocities and also being able to control the velocities of the players and enemies upon the impact(s) ) but I feel if I can get this one thing done first then I can start trying to figure it out more myself. If I'm not being clear enough, please let me know.
For example, if I were to have a dynamic box (no localtensor, so no rotation, represents a player character) with a mass of 1 unit constantly moving forward 1meter(s)/second to collide with another dynamic box (rotation enabled, represents an object that can be interacted with) that has a mass of 1 unit on a flat plane, the expected behaviour is that the object box is pushed along with the box.
This is sort of what happens, although it is not perfect because it seems the object box gets "snagged" by the triangle data's lines on a flat plane mesh I am using (happens whether it is a mobile mesh entity or a static mesh. The mesh is flat so there is are no problems with that, using a few box colliders for the floor is the same effect) for the floor and then strays from the direction it is being pushed in, sometimes a little violently, and may even be thrown in the air a little. I don't know if that is supposed to happen but for now it does not matter as much to me as everything else I will explain. So for the most part the behaviour is expected.
If I increase the mass (twice, thrice, etc.) of the box that represents the player the behaviour that is expected also happens for the most part (distance the object is expected to travel is somewhat inconsistent), that the object box is flinged ahead more as the mass of the player box increases.
Now, this is all well but I need to be able to create a different sort of behaviour. I need it so that no matter what velocities the player box may be traveling at, or even what mass it has, the player box should gently brush aside the object box instead of flinging it upon impact (because the velocity of the player character will be well above 1 meters/second there will be a lot of force applied even at similar mass relationships) and not lose it's own velocity (setting the object box's mass at a higher ratio than the player box yields the effect that I want for the object but not the player as the player now does not move at it's full velocity set every frame). The way I am currently moving the player box is by setting the linear velocity every frame (the change between desired velocity and current velocity is added to the current velocity every frame, works better than setting the velocity directly because gravity starts becoming an issue) and it works just fine for moving it so I would like to continue to be able to do this.
I think a good way to describe what I want is something that I have tried and seems to have the similar effect I want. That is, I used a kinematic box to represent a player, and used the character controller to represent the object. By setting the controller to ridiculous settings for traction, forces, glue, etc. I was able to have the fast moving kinematic box (just moves in a back and forth pattern, and it is kinematic because I don't want it to lose any velocity upon hitting objects) push the object gently along with it in it's path and not fling it across the scene (which is what happens without adjusting the settings). The issue is that I don't think I need a character controller for every physics object like that in the game, it would get ridiculous to have hundreds of controllers representing some debris objects, and I'd like to be able to use dynamic entities for the players/npcs so they can move each other as well (perhaps not in the exact same relationship as this though, but simialrly),
So is there a way I can achieve this sort of relationship with the "player" and "object" dynamic entities? In this particular case, to restrain the impact the player moving has into the object entities, ensure the player does not lose velocity upon impact, and keeping the relationships of other object entities amongst themselves the same. I feel like the answer might lie in the collision events that take place during the physics calculations ie. PairUpdating, but I really don't know how I would do it even with that. Also, this is only one step of the way for me as I mentioned earlier that I plan to have players/npcs interact with each other in a similar way (players colliding into enemies/npcs but not flinging them away because of mass/velocities and also being able to control the velocities of the players and enemies upon the impact(s) ) but I feel if I can get this one thing done first then I can start trying to figure it out more myself. If I'm not being clear enough, please let me know.