UE5 - Simulate Physics causes Actor to fall through ground when player interacts - unreal-blueprint

I've set up a simple code that allows the player to use a line trace to pick up objects and assign them to one of three sockets on the character mesh.
I then set up the ability for the player to cycle between items in 'pockets' and items in hand, as well as dropping the items.
Everything works fine. The player can pick items up and drop them, as well as cycle them between hand and pocket, as long as 'Simulate Physics' is set to false on the item that is being picked up. Anything the player interacts with that has 'Simulate Physics' enabled falls through the floor upon interaction. this is the physics settings of the object
I need the code to allow me to pick up physics items. I believe that the 'Set Actor Enable Collision' is the issue as when this is not in the loop the Actor does not fall through the ground, however I need to disable the Actors collision with the player otherwise movement is hindered. I don't understand why the 'Attach Actor To Component' doesn't hold the Actor in place when the Actor 'Simulate Physics' is set to true.

Related

LibGDX / Box2D: How to keep track of active Contacts between bodies?

I'm making a 2D (side view) car game with LibGDX using Box2D. The car has a front wheel and a rear wheel and it's "AWD". I would like to render a dust effect to each point where a wheel touches the ground when the player is "burning rubber". To do this, my plan was to
Implement ContactListener, and in beginContact(Contact contact) method find the Contacts where one of the fixtures is ground and the other one a wheel of the car.
Save these Contacts to a (wheel-specific) array, which is supposed to contain the active Contacts of the wheel (the wheel can touch the ground in multiple points, hence an array is required).
During each render call, for each Contact in each wheel's array: Get the contact position, and calculate velocity difference between the wheel body and the ground body at that position. If the length of the velocity difference vector is greater than a certain threshold, then draw the dust effect (using the velocity difference vector to define the speed and angle of the dust particles).
When endContact(Contact contact) of my ContactListener is called, remove contact from the array.
The problem is that LibGDX appears to use the SAME Contact instance for every Box2D contact, rewriting the existing Contact even if it's still active! This means, for example, that if the rear wheel touches the ground first and the front wheel after that, the Contact instance I saved to the rear wheel's contact array gets overwritten with front wheel's contact properties. Another problem is that when I receive endContact, I don't know which Contact really ended.
Have I understood something wrong, or is this how LibGDX is supposed to behave? Is it possible to somehow adjust this behavior, or is there an easy workaround?
(One option that comes to my mind is to keep listening to beginContact and endContact calls and just keep track of the ground bodies/fixtures that are touching each wheel, but then I would have to calculate the contact points manually each frame, which sounds somewhat difficult, expensive, and redundant - because Box2D anyway calculates it at each world step).
Maybe you can create a MyContactListener implementing the ContactListener class.
The MyContactListener class contains a MyContactInventory object which is a Singleton object containing your Contact Array and a couple of convenient method:
addContact
removeContact
The beginContact and endContact add/remove Contacts to your Array using the convenient methods above.
Then you call world.setContactListener( new MyContactListener());
Hope it helps!

Level part changing in an entity system based game

I am currently working on an entity system based game using artemis and libgdx and I am wondering how I should handle level changing in such a configuration.
For example, with a Mario-like platformer:
First Mario starts the level, the engine instantiates a new World() loading the tilemap and initializing all the objects.
What if Mario goes through a pipe? The world inside the pipe is a new World()? or does the camera only focus on another part of a world?
If we have a new world, artemis doesn't allow detaching an entity from a world, so may I clone the player entity and add it to the new world?
Does someone know how to handle this kind of level part changing (Mario's part / Abe's odyssey screens)? What are the common ways to achieve this using an artemis-like framework?
Think about decoupling the building of each particular level so that your world object can take in a specific level that could either read in the position of entities like the mario blocks and pipes or just define them in that specific level class. Allow your world to set new level as a method or you could create a new world object each time and unattach the old one for garbage collection. For something like the world in the pipe if you didn't want to have to load it while the player was already in the level than you could build the room or area somewhere off in the distance and use the pipe to teleport the character to a spot inside the room.
I would create some LevelTagComponent and add it to all entities that are level-specific. Custom Manager should do the rest - turn off some entities when Mario goes into a tunnek or remove them when level is being completely changed.
I finally decided to add a room object layer defining rectangles (see picture below)
Each room is a rectangle with it's x, y coordinate and width, height dimensions. Each room defined the bounds where the camera is allowed to move, if the player intersect with another room, the camera slide from room n to room n+1 along the x axis or the y axis, if the room is bigger than the screen, the camera is allowed to scroll.
I have been able to improve performance and to solve a lot of issues using this approach, it is possible to only process the entities contained within the current room instead of calculating the full world at each frame.

Draggable object with multiple boundaries

I have my player dragged around the stage. If the player hits any object(All perfect rectangles) that I lay out in a movieclip, I'd like the player to hit a wall and stop moving. What's the most efficient way to write this?
Do I loop through all the points the player can't hit?
There are built in methods for hit testing, you loop through all the objects you want to hit test against (make each it's own sprite or hit test the entire sprite that contains all the parts against the object depending on what kinds of info you want to have. You may also want to rig up your own custom Sprite that has hit regions for the left right top and bottom to determine which edge the player has hit.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject()
Multiple hittest AS3

Has anyone experienced side effects (including performance issue) of using getObjectsUnderPoint?

Before I go making major change in my ongoing game project, I just want to hear from others if anyone has found any issues with getObjectsUnderPoint() function of the DisplayObject?
Update:
Not just the performance issue but any other limitations of using it (like it doesn't detect certain type of UIelements (just as example))
I will have three layers in my application (which an Isometric game)
Background -- This is just a background which stays in the bottom, has nothing to do with game
Middle Layer -- This is the playable area, Here all my game elements will be placed on this layer
Top Layer -- This is one dummy transparent layer covers entire playable area which interrupts all the mouse events. This is where I want to use the getObjectsUnderPoint()
So, player wants to click on the element, the top layer will interrupt the mouseevent and then check if there is something placed or just a plain background and take appropriate action like, notify the underneath object.
This really doesn't require to be done this way because I could simply add moues events for all those items placed on the map directly but because I would be using getObjectsUnderPoint() anyway to check if there is anything beneath the item.
If anyone can explain how this function works then it would be little easy for me to make a decision.
There was one annoying problem though. I don't know if they fixed it or not. At least it was there in 10.1 times.
If you have a container and you scaled it container.getObjectsUnderPoint will return wrong result. All the time. So everywhere where I needed getObjectsUnderPoint I had to call it from stage to get proper result.
It's an incomplete function. It returns graphical objects under the mouse, NOT all potential mouse targets for event or interaction purposes. It actually requires complex logic to examine the array returned by getObjectsUnderPoint to determine the mouse target, because the appropriate target (the one Flash would choose if you actually clicked that point) may not be in the list.
First you'd have to examine the object array in reverse, since the items are ordered back to front. You'd have to examine each object's entire parent chain, looking for a parent with mouseChildren = false that would cause it to intercept the event and become the target. Whether or not such an object is found, this final object you arrive at must have its mouseEnabled property set to true, otherwise you must skip it and move on to the next object in the array, which would be, for example, the next sprite or shape behind the one you initially checked. While going through the list, you must notice when the parent changes, at which point you need to assume that all children of that common parent had their mouseEnabled property set to false, in which case the parent would become the next candidate. This is actually extremely complicated, because you're working backwards in a bottom-up approach with an incomplete set of objects that was generated from the top-down.
To get actual potential mouse event targets, consistent with the default dispatching logic... it is actually easier to start from the stage in a top-down manner and walk backwards through the display hierarchy in a depth-first search, checking mouseChildren to determine whether you need to step into children, and checking mouseEnabled if it's to be a target, otherwise stepping into the container's children and repeating the process from back to front again. This is much more accurate, complete, and staightforward. The only problem is you have to code it yourself.

Flixel - How do I make FlxGroups appear on just one FlxCamera?

I have a Flixel project with multiple FlxCamera's. One of them is the main play area, and another is the radar display within the HUD to the right of the main area. I want to add a layer (FlxGroup) to just the radar camera, and I also want to exclude my other layers from the radar camera so they don't randomly show up in the radar's area.
My question is, how do I tell the cameras to only show objects in certain FlxGroup's?
Figured this out on my own. Each object needs to be given a reference to an Array containing references to the FlxCamera objects you want it shown on, and this needs to happen (usually) when the object is first made. The first time a FlxObject calls update(), if its cameras is null, it assigns FlxG.cameras as a default, which means all of the active cameras will display the object.
I did this by making a few static Array's in my Main class, one for each camera group, and then in the constructor for my various classes, I would set their cameras variable to point to the corresponding Array.
The biggest frustration: Currently FlxGroup does not pass its cameras on to its members. Hopefully this will be added into future versions of Flixel so that FlxGroup's can be assigned a camera group and have all their children also automatically assigned the same camera group.