How to make a spike reset back into place

Hey, so I’m making a simple side scroller for one of my classes. I’m very new to Unreal and I don’t know a whole lot about programming in general. I’m trying to make a spike that as soon as you go under it, it falls and damages you. The part that I’m struggling with is how to make the spike reset back into its original place after it falls, so it can fall on top of you again.

Here’s the blueprint I made to make it fall when the player hits the trigger box

Hello and welcome to the forum :slight_smile:

While simulating physics might seem like a very sensible way to do this, the are some problems with the approach.

I am guessing you don’t want the trigger box to move, so you probably do not want to simulate physics on that regardless.

As for the box (spike?), physics simulated bodies do not play well with character capsule colliders, when/if your spike hits the character it is going to bounce off in a manner you probably don’t want. Essentially, the character’s capsule is unmoveable by interactions with physics bodies and will impart a large force on any coming into contact with it.
Simulating physics will also detach the component from its parent component, which depending on your spike actor setup maybe undesirable.

Much of this may be irrelevant depending on your character and spike setup, is the player’s character a Character with a capsule collider?

Ignoring all that and just proceeding on the path you are on:
Presumed spike actor setup:

Add variables to store original and ending position and rotation:

Record original position/rotation in Begin Play:

After the drop delay, record the ending position/rotation:

Then add a timeline node, double click it and set the ‘length’ (time in seconds for the reset) and add a float track that goes from 0 to 1:

Back on the event graph, in the timeline update, lerp position and rotation back to original values, and when it is finished re-attach the spike to the scene root (if detachment is a problem) and reset the Do Once node:

Et voilà.
Probably not the solution you are looking for, but will “work” with the physics based drop.

I just tried this, and it’ll work for what I’m trying to do. Thank you so much, this was driving me crazy! :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.