Apparently what I’ve set out to do is everything completely against what Unreal Engine’s preferences, based on days of scouring the forums trying to piece together how to go about doing this. I’m trying to create a projectile setup that has “random flight” characteristics to it. It may not sound realistic, but it’s realistic when you consider this a airsoft gun, rather than a real rifle.
I’ve added several components to recreate a “simulated” airsoft gun - including Hop Up and Variations. Hop Up is a backspin that is create on the projectile in airsoft - rather than letting gravity take it’s course, it uses the [Magnus Effect](Magnus effect - Wikipedia to lift the projectile in order to give it some more range, with the caveat that it’ll have a steeper downward force at the end of it’s flight. You can see an example of the flight path here.
Now, with all that out of the way - I’ve managed to get the flight path perfect. On Fire, Projectile is spawned at the barrel, the Hop Up is imitated by a TimeLine+HopUpAdjustment to an AddForce Node. Additionally, 4 sets of Random Floats are also added in order to create an “inaccuracy” effect, 3 of them output into the XYZ of an AddImpulse Node, and the fourth as an added modifier to the AddForce. This creates a very realistic flight path for an airsoft rifle.
The problem is collision. The only thing that the projectiles seem to collide with is the ground, they will always pass through objects. I’ve double checked several dozen times, the world objects are set to Collision Enabled (Q&P) BlockAll.
Currently the Projectile is set up as Mesh(root), CollisionSphere, ProjectileMovement. I’m at a loss as to how to proceed from here.
I can confirm that yes, objects placed in the world do have collision boxes.
I managed to do some more troubleshooting by adding some Debug Spheres - both to the Root Mesh, and to the Collision Sphere. The Mesh, as expected, will shoot as intended - however the Collision Sphere drops like a rock out of the barrel… and as of writing this, found something strange as well. The AddForce and AddImpulse modifiers were not applied to the Collision Sphere - I apparently have misunderstood that having the collision sphere tied to the mesh would follow the mesh, but apparently that’s incorrect.
I’ve tried swapping the root to the Collision Sphere, however I can never get the physics to be the same, but that might be more troubleshooting.
So you use physically based objects, not just “Projectiles” - those are two different things
You need one thing to control the collision, now as you know that your collision shape falls - disable physics for it, physics is necessary for the main part that will be the root (not necessarily the Collision Sphere), everything else can have it turned off but needs to be attached to the Root (either manually in Actor or using BP’s)
So - whatever gets your force to shoot bullets out can have physics, the rest parts (collision check, particles, sound) just have to be attached but besides this those need nothing special to work, they will just follow their parent component
So I’ve managed to get somewhere with this - firing at a thin object in the world, most likely results in the mesh projectile passing right through. If I fire it at a near-perpendicular angle at the object (rather than firing at 90°, firing at a 5° angle), then there’s a 50/50 chance that the projectile will collide and bounce off. Provided the current “range” I’m using to test the physics are firing at thin planes, there’s objects in my world that are not much thicker, and have already confirmed that they will pass through the objects (even multiple) most of the time. This looks like a problem with detection in the tickrate?
I’ve seen people talk about setting up a trace channel to detect last frame and current frame to determine if the projectile has collided with an object.
The problem I find with this solution is that, well, I have yet to find a guide on how to go about setting that up, as well as most of those projects I’ve seen expect that the projectile is going to be destroyed on collision - I’d like to still have the projectile bounce off surfaces, but I’d set it to stop acting as a “live” projectile after a bounce, but still bounce after collision.
Besides the traces they use theres a special option for that called “CCD”
Continuous Collision Detection
It’s available in a drop down menu of Collision settings of a component
Trace is good as it will not miss the point, but you need extra measures like travel time, velocity and location of the Enemy to be sure that the bullet would actually hit him (line trace is instant in comparison to a flying bullet)
Also making the Collision Detection somewhat bigger isn’t that bad, or you can use rather a collision Capsule/Box to make it longer rather than uniformly big sphere
@Nova1395 How did you set up the curve on the timeline for the hop up? I’m looking at doing the flight of a golf ball and your bullet flights look similar to what i want