# How to change the location of a static mesh with event tick c++?

**URL:** <https://forums.unrealengine.com/t/how-to-change-the-location-of-a-static-mesh-with-event-tick-c/458238>\
**Category:** Asset Creation\
**Tags:** event-tick, unreal-engine, CPP, question\
**Created:** [November 10, 2019, 11:04am UTC](https://forums.unrealengine.com/t/how-to-change-the-location-of-a-static-mesh-with-event-tick-c/458238 "2019-11-10T11:04:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ECTheHunter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ECTheHunter](https://forums.unrealengine.com/u/ECTheHunter)\
**Post date:** [November 10, 2019, 11:04am UTC](https://forums.unrealengine.com/t/how-to-change-the-location-of-a-static-mesh-with-event-tick-c/458238/1 "2019-11-10T11:04:19Z")

</div>

I want my weapon mesh(static mesh) to kickback every time I press an input. I also need it to come back. Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [November 10, 2019, 11:20pm UTC](https://forums.unrealengine.com/t/how-to-change-the-location-of-a-static-mesh-with-event-tick-c/458238/2 "2019-11-10T23:20:34Z")

</div>

you need to make class time varbale that will track time (lets make it t for here) by adding DeltaTime each tick to it, then make a if which will do something for specific amount of time (here it’s 5 seconds) you can also use FMath::Min to make t flat in to maximum value:

```
void AMyActor::Tick(float DeltaTime) {

    t += DeltaTime;

    if(t =< 5.0f) {
        SetActorLocation(BaseLocation + FVector(0.0f,0.0f,FMath::Sin(t*10.0f)));
    }

    Super::Tick(DeltaTime);

}

```

Now inside if put mathematical function of animation with t being timeline axis. For sake of simple example i made simple sinusoid animation which will make actor move up and down. BaseLocation is root point, a actor actual location. You reset animation just by setting t to 0 in other function.

I think in your case most simple way would be use of linera interpolation functions, which will move actor from one delta point ot another over time:

> **[Lerp](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Core/Math/FMath/Lerp/)**
>
> Overload list

---

<div class="post-metadata">

**Author:** ![ECTheHunter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ECTheHunter](https://forums.unrealengine.com/u/ECTheHunter)\
**Post date:** [November 11, 2019, 4:25am UTC](https://forums.unrealengine.com/t/how-to-change-the-location-of-a-static-mesh-with-event-tick-c/458238/3 "2019-11-11T04:25:45Z")

</div>

Thanks a lot.
