# Clamp Movements to Screen Limits (left/right only)

**URL:** <https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716>\
**Category:** Game Development\
**Tags:** unreal-engine, question\
**Created:** [March 14, 2023, 5:13pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716 "2023-03-14T17:13:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveB3346](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaveB3346](https://forums.unrealengine.com/u/DaveB3346)\
**Post date:** [March 14, 2023, 5:13pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/1 "2023-03-14T17:13:45Z")

</div>

Does anyone know how to restrict the movement of a pawn to just move within the screen limits. For example I am trying to build a simple Space Invaders game, where the player is a floating pawn and can only move left and right. I need to be able to do this in blue print, but i’m struggling to find much material on this on line. Any help massively appreciated.

---

<div class="post-metadata">

**Author:** ![rokenrock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rokenrock/32/1040844_2.png) [@rokenrock](https://forums.unrealengine.com/u/rokenrock)\
**Post date:** [March 14, 2023, 7:14pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/2 "2023-03-14T19:14:44Z")

</div>

I think the easiest way to do this would be to just add invisible colliders to the walls.

---

<div class="post-metadata">

**Author:** ![Mind-Brain](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mind-brain/32/906573_2.png) [@Mind-Brain](https://forums.unrealengine.com/u/Mind-Brain)\
**Post date:** [March 14, 2023, 7:23pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/3 "2023-03-14T19:23:17Z")

</div>

Hey @DaveB3346!

@rokenrock is right! Just use 4 box colliders in your level that block pawn movement, and make a box out of them! That’s by far the easiest method, don’t worry about a clamp! 🙂

---

<div class="post-metadata">

**Author:** ![DaveB3346](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaveB3346](https://forums.unrealengine.com/u/DaveB3346)\
**Post date:** [March 28, 2023, 3:23pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/4 "2023-03-28T15:23:38Z")

</div>

thanks guys very much for your help, it does have to be a clamp though in this instance (its part of  
the project brief, to have a working screen clamp)

---

<div class="post-metadata">

**Author:** ![rokenrock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rokenrock/32/1040844_2.png) [@rokenrock](https://forums.unrealengine.com/u/rokenrock)\
**Post date:** [March 28, 2023, 4:41pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/5 "2023-03-28T16:41:32Z")

</div>

Collision is, for all intents an purposes, a clamp. There’s one (possibly two) clamp per collision face. I’m pretty confident your professor won’t mind the difference.

Without using collision, it’s bound to look janky. If you’re using set actor location for movement, you can just use the mathematical clamp node before setting. Excluding that and collision, any other method would be jittery.

---

<div class="post-metadata">

**Author:** ![DaneGull](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaneGull](https://forums.unrealengine.com/u/DaneGull)\
**Post date:** [July 12, 2023, 10:10pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/6 "2023-07-12T22:10:05Z")

</div>

Did you ever figure this out? I love how you got a bunch of non-answers.

---

<div class="post-metadata">

**Author:** ![rokenrock](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rokenrock/32/1040844_2.png) [@rokenrock](https://forums.unrealengine.com/u/rokenrock)\
**Post date:** [July 12, 2023, 10:41pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/7 "2023-07-12T22:41:11Z")

</div>

The answer is to use collision. Don’t reinvent the wheel.

> [@rokenrock](#):
>
> use the mathematical clamp node before setting

Either way, a clamp is the main component of this question and was mentioned.

  

If you need more specifics:  
use a combination of the clamp, ConvertWorldLocationToScreenLocation, and GameUserSettings-\>Resolution nodes.

---

<div class="post-metadata">

**Author:** ![DaneGull](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DaneGull](https://forums.unrealengine.com/u/DaneGull)\
**Post date:** [September 21, 2023, 4:03pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/8 "2023-09-21T16:03:16Z")

</div>

> [@rokenrock](#):
>
> clamp per collision face

the answer was to clamp the distance the player can go from a set vector in the middle of the gamespace. no collision at all or screen location node.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [October 21, 2023, 4:03pm UTC](https://forums.unrealengine.com/t/clamp-movements-to-screen-limits-left-right-only/790716/9 "2023-10-21T16:03:32Z")

</div>

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