Kart Racer Projectile behavior.

Hi, I’m working on a fun Kart Racer project at the moment. I’m relatively new to unreal engine and visual scripting but I would say my skill level is intermediate.

I wanted to make a projectile similar to how the green shells operate in Mario Kart.

This would be bouncing off steep > 70 degree walls while climbing or descending anything less than this and maintaining all X/Y axis velocity until it either collides with another destructible or bounces a certain number of times.

I have the projectile spawning from an arrow attached to my player pawns forward orientation at a speed that will always be greater than the players max speed.

The projectile itself is using the static mesh shape_taurus that comes with the engine for the time being.

To this I have added the following components;

Rotating Movement,
Physics Constraint,
Sphere Collision.

While some of these may not be needed for the behavior I want for this example I do want a master projectile object that will act as the template for the behavioral needs of all of the other projectiles that I add to the game.

I have not done any scripting for it so far as most of the functionality I need is already included in these components. However I have been unable to limit the Z axis movement of it. Currently the projectile will bounce in any axis keeping the momentum in whatever angle it bounces. Limiting it’s Z axis movement would stop it climbing the various heights of the level. Would I be correct in assuming I need to use walkable slope behavior for the object to decide whether it bounces or climbs? How to I get it to stay close to the ground and unable to bounce off it while maintaining it’s X / Y velocity? Also would I better off using the static mesh for collision detection or would the sphere be more efficient?

Any help would be greatly appreciated. Thank you.

There are several “Hover” tutorials that will use line traces to trace down to the ground, making the blueprint “float” above ground at a certain height. You may find those useful in the Z restriction part. I believe, it has been awhile since I have seen the video, that Dampening is a part of it as well. You will likely want the one that Epic has done.

Thanks Yggdrasil. I should have thought of that since I saw a hover tutorial a while back. I’ll dig up some tutorials and see if I can apply them to the object. Thanks for the suggestions.

Messed around with this but can’t get it to work. While the hover component works, it does not work in combination with the Projectile movement component. The linear damping needed to stop the hover z forces getting out of hand also dampens the projectiles x/y velocity which is initially set by the projectile movement component.

It doesn’t seem to be a very efficient way of doing this either as it’s running a tick for each projectile and you may have to add multiple hover components to a static mesh to get it to behave properly.

So back to the drawing board.

I think the simplest way would be along the line I was going. The projectile behaves well. I just need it to only bounce off walls, not the ground, and to climb certain angles. There should be a way of doing this using only hit events which should be less demanding than tick. I’ll keep searching for the answer. I don’t think my blueprinting skills are good enough for this yet.

Having played around with physics materials I pretty much got the desired effect by having separate physical materials for the wall, floor and projectile. The floor now has 0 friction and 0 restitution with the projectile while the wall has 1 restitution so I get no bounces on the floor now and 100% energy conserving bounces with walls. It also slides on the floor now. The only thing left to fix is the projectile ramping into the air off small slopes and lips which I assume can be fixed with walkable slope and some sort of z axis modifier. Still any input welcome here.

I don’t think I would do this with physics to be honest, too unpredictable with different maps, like you said it might shoot off a ramp or something.

I would just create a regular static mesh and it’s always got a fixed speed anyways just give it it’s starting speed and direction and fire it off. Set it’s Z position and rotation to offset from the road below and to take the angle of the road (you can do this with 2 line traces, 1 directly down and 1 at an angle in front, use trigonometry to calculate the angle it should be to match) and do a basic reflection off the wall in pretty much the same way.

Hi Zoltan. Thanks for the reply.

Your suggestion is interesting and possibly the best way of solving this although I could foresee problems using this method as well. For example a flat road meeting a steep 45% ramp. Also would drops teleport the projectile to the surface below? Also if I am calculating wall bounces would a single line trace suffice? Any side of the projectile could hit a wall. I suppose I could make the forward line trace component always face the travel direction of the projectile. I am unsure of how to implement it as well but I will give it a go later on.

That’s why you do the 2 line traces, the 1 out in front will give you the change in angle so you can adjust it. It’s unlikely that you would go at such an aggressive angle anyways so you just adjust the rotation of it and if its floating a bit off the ground you should be fine.

If you are animating the static mesh (spinning the shell around or something) then you are just doing a trace along it’s current path, so you want to get it’s forward vector. So you just do a line trace from there and calculate the angle of incidence and then send it off that way again.

Thanks for the help, useful info there. How do I offset it’s position from the road exactly though? What function? I understand how to set up the line trace components. How do I use the info from these to offset the projectiles angle and position in relation to the surface and the bounce angle on walls. It’s a bit over my head in terms of being able to blueprint this yet. It sounds like it would be quite a big blueprint when I was really hoping for component manipulation and maybe minor blueprint work while letting the physics handle the rest. My mathematical abilities are not the best either. Do you know of any tutorials that cover something similar?