I’m having incredible difficulty getting the inbuilt physics to work the way I want, even though what I want is quite simple. Instead I would like to create my own physics code, as it is quicker than wrestling with the current setup. My plan is to just use SetActorLocation etc for movement, rather than AddForce etc.
What I would like to do is override the behaviour that happens when there is a collision so that I have more control over what happens when two bodies collide.
For example, what I would like is a HitEvent to be called (so that I get a normal for the collision), but no force generated on the bodies. Is this possible?
If you’re manually setting actor locations, you’re not creating physics code, you’re just moving actors around. As far as I know HitEvents only work with physics simulations. What are you trying to do exactly?
I’m just trying to do something I thought was simple - create a player ship, and then attach a staticmesh to it. However everything I try seems to produce unwanted results - Firstly I found a bug that gave me an incorrect Mass when I did that, depending on the collision settings. Then it moved the center of mass to the wrong location. I managed to fix that by bypassing the UE4 code and hooking into PhysX. Then when I fixed that it again altered the mass of one component which I’ve been unable to fix. On top of that I can’t get the collisions on the individual components to work. It’s an utter nightmare!
Overall it’s taken me a week to (still not) achieve something relatively straightforward. So I’m now trying to insulate myself from the UE4 code to the greatest extent possible. Hence all I want is some collision info.
At this stage the only thing I can think of is to use BeginOverlap and trace a line between the object centers to a bounding box and make the assumption that they are colliding at that hit point. I know that is incorrect but it’s the only solution I’ve been able to come up with so far.
I’m unclear as to what you need physics for, you certainly don’t need any physics to attach static mesh components to a ship. I assume it has something to do with what you’re doing with the ship after the components have been attached?
Are you attaching the static meshes as child actors or as static mesh components of the original actor?
Hi PixelOmen, thanks for trying to hep!
I use physics to interact the player ship with the world. My main problem was trying to weld a static mesh to an actor, using AttachTo. In the end I ended up using a PhysicsConstraintComponent instead of Attaching with weld and everything now works fine.
Basically welding threw everything off (mass, distribution, collision) and while I was able to fix some of those problems, the physics constraint was a lot easier and seems more reliable.
For what it’s worth, if you use MoveComponent on your components with bSweep = true then if there is a collision it will generate Hit events, without exerting recoil forces. Things will still block though.
Also, there is a callback in physX called onContactModify which can be used to alter the forces, but it’s currently not exposed in UE4.