Is it possible to create a BP where a character can attach itself to a wall and run across it? For example, thinking about the Sonic games; When Sonic runs around a loop, would it be possible to pull off in a blueprint? I have no idea whatsoever on where to start!
If someone could point me into the right direction; I’d be extremely grateful!
my first idea would be to run a trace downwards, get the normal from the hit and align the pawn to that. probably a very crude method with some issues along the line, but I don’t see why it wouldn’t work.
I believe you could achieve this by constraining plane movements and play with forces.
Luckily, UE4 have variables for planner movements ,you can find it if you go to defaults tab in your character then to planner movement.
from there you can constraint the player movement to a particular plane
I’ve found it in the Defaults tab, but it doesn’t let me let around a loop for example; He gets to a specific part of the loop (90 degree) and can’t run up anymore. I’m trying to figure out how to get it to ignore gravity while the player is on the loop.
But around a 360 loop, wouldn’t this mean I’d have to add force 360 different times in order to make the character stick to the loop completely?
I tried doing this, but the Blueprint doesn’t seem to function AT ALL. Weird. I mean it compiles fine, saves fun, casts from GravZone1 (Trigger Volume) to player, but the player doesn’t get affected by the gravity. I did a “Print String” to find out if it’s actually working. The “Set Gravity” target doesn’t seem to be working.
There must be a solution; a simple one that I’m overlooking. I mean I have a loop mesh and a character, surely there’s some simple thing I’m missing where when the actor touches the mesh, he clamps to the mesh?
Good question. I have never tried to apply gravity when the player is colliding with a large complex object.
I only know on simple objects you can get the “normal” direction from a collision which still might work in this case.
Try using a collide event and getting the normal from it so you can apply your gravity inversely.
Still no luck, the player just doesn’t want to be affected by the Gravity… Weird. Maybe there’s a way to just simply connect the player to the prop while he’s touching it? I can’t seem to find it but it must exist.
I guess one way to make this work could possibly be to take control away from the player, switch to Matinee with a custom animation of going around the loop, but that’s not an ideal solution; Especially if I wanted two players to play.
I think the approach of transitioning to and from an animation might be the best approach here. You can decrement a variable if the player stops pressing forward, and switch back to the standard player control to break out of the animation when the player lets go of the controls at the top of the loop, or perhaps just isn’t going fast enough.
But can you control a player controller with matinee and instantly let them have the control back? I didn’t think this was possible.
EDIT: Just tried this with Matinee; It won’t let me hide / remove / edit the player. I tried animating the player pawn but nope, wouldn’t even let me add it into Matinee. Am I doing something wrong there? I tried deleting the player, hiding the player and using an animated static mesh of the character running over the loop; But the player just won’t hide / remove / move, the static mesh does, but the camera in matinee and even in the player won’t respond to what I’m trying to do.
EDIT EDIT: I noticed Sonic GDK/UDK managed to pull this off in UDK; But I didn’t use UDK and I can’t find where they would’ve set their loop to attach to their Sonic. I tried looking in their Kismet, but couldn’t find anything and I tried looking through the UnrealScript, but their pawn is just a regular pawn.
Gravity doesn’t affect the character when they’re walking, only falling, flying, and swimming.
If you want to take a sort of physical simulation approach, here is my suggestion:
Allow a walkable surface normal up to right about 90 degrees (vertical)
Set MaintainHorizontalGroundVelocity to false in your CharacterMovementComponent. This means movement speed will be relative to the surface rather than a flat plane.
Detect when you hit a surface that is too steep and you start “falling” (you should get a OnMovementModeChanged event).
At this point, send the character upwards with a velocity tangential to the surface where you stopped being able to walk. You might try GetPhysicsLinearVelocity() on the capsule, or extrapolate from the character movement component velocity (which is only going to be in XY since it was walking; this is a little confusing I know, but the magnitude should be correct).
Basically the goal here would be to run up as high as possible, and then launch the character upwards in falling mode so that they basically undergo a physics sim that should cause them to glide around the top of the loop. If they make it around to the other side, they will hit a walkable surface and resume running. If they didn’t have enough speed, they could fall off the loop at some point.
Since you’re falling, you can modify gravity if you like (note the GravityScale variable on CharacterMovementComponent that you can use rather than change world gravity, which would be safer for multiplayer). You also may want to fiddle with UpperImpactNormalScale if you find that the collision is a bit strange on the upper portion of the capsule (probably just set it to zero).
An alternative could be to place a trigger that is activated only on appropriate velocities (ie moving up the steep part of the loop), and then attach the character to a path that takes them around the loop to the other side (this is probably the Matinee solution). This would be a bit different than Matinees in UE3: you’d want to attach to an actor that interpolates using a matinee actor along the loop, and try to control the speed based on the initial velocity.
So I tried following your steps; But as I realised as I put it together; Since this is taking over the falling state; When a character jumps, he immediately flings to another side of the map. Is there anyway to stop this from happening; Do I have to create a custom state? But even then, if a character were to fall to the side of the loop as he was looping, he could possibly fling off to another side of the world. I suppose I could fill that part in with a blocking volume, but this volume would overlap the entry / exit points of the loop thus making that most probably the least effective way of doing it.
Here is the blueprint, in case I’ve totally messed up:
Ah so I guess the trick is knowing that this falling state is happening because you have run up your loop, rather than something else (like manually jumping or running off the edge of something).
You might try tracing forward in the proposed velocity first, to see if you actually hit geometry that you care to use this with. So sweep a capsule forward a short distance and either check the type of the actor, physical material, impact normal, etc and then decide if you want to add this velocity or not.
One more thought… it might be safer to add a trigger volume where you automatically launch the character (similar to the matinee idea). It might pretty complex to try to detect all the conditions in the other approach. Whenever the character is in the trigger, you could check the velocity and then decide whether to launch them. Or you could go with a hybrid approach-- on entering falling mode, see if you are in the volume under the correct conditions. Just another idea to play with!
When the character hits the top of the roof; As he’s in Falling mode, he’s not running so he doesn’t look right, so I’m thinking of going the Matinee route; But I can’t find a write-up of manipulating player controlled pawns in Matinee (Taking control away and giving it back when Matinee has been complete).
Can anyone point me in the right direction in that respect?
EDIT: I’m going to try hiding the player controller, spawning a fake mesh (Running anim) doing the loop, putting the player in the new area and the unhiding him. I’ll let you know how this route goes.
So temporarily, I’ve used the Matinee way; Seeing SonicGDK (UDK game), I know that the psyhics I’m after is possible; But I’ve ripped apart Kismet and all the UnrealScript files and I can’t find their trick; So for now, this is how it looks (I’ll implement moving the player while the matinee is playing and launching him off the loop in a bit). It’s a shame that the running around the loop doesn’t seem to work from all the help you guys have given me; but thanks all for the help.
If anyone else has any suggestions, please don’t be afraid to say so! I need all the help I can get!
Video of temp Matinee (I used a Sonic mesh for good measure, haha):