Clamp mesh rotation

Hello everyone,

I have the following problem:

The red box is sliding on a slope, like in ski. I am trying to limit / clamp its rotation on the Z axis, so it cant turn after reaching 90 or -90 degrees. What I did with the following code was try and limit how much I can turn it based on my mouse input, and to some extent this works. However, this does not clamp the mesh from actually turning when influenced by any outside source (i.e hits an obstacle).

How can I solve this ? And is there a better approach to my problem ?


You also need an interp on tick to make sure the local rotation is clamped:

1 Like

Thanks so much, I will try this and come back with feedback :smiley:

1 Like

It worked like a charm. Thanks a lot!

1 Like

I am back with another issue, which has been bothering me all day. I tried fixing it alone trough various means, google didnt help, so I have to resort to asking you guys for help.

On the same project as above, I need to make a check if the (red) pawn is on the ground or not. The reason for this is that I want it to be able to break while going down the slope, but I dont want it to break mid-air.

So I setup this to check if it’s on the ground:

and then before applying the break I make the check:

Now, this works. For a while. When the pawn is falling from a ramp, or whatever, the AIR print string activates, and when it hits the ground (Landscape), it prints into GROUND. Also the breaking logic works flawless. But after a short while, especially after I just run out of placed ramps, and it just keeps going smoothly on a slope, it sets the AIR back. Sometimes it transitions back to ground, but I cant seem to replicate when exactly.

The collision box that does this check is just a cube placed beneath the pawn, I tried changing it in all shapes and sizes, to no avail.

Here is a picture of the slope, so you get a better picture:

Hi, sorry for the delay.

The standard way to do this is with a downward line trace. It works a lot better than collision boxes :slight_smile:

I searched on google and here, but couldnt find a reliable way to do it. Could you point me to a tutorial please? :confused:

This is how you do a downward trace from the player:

The -500 is how far to go down, you might want to tune that.

Also, you need a reference to the landscape actor ( see that on the right ).

You can try this: Unreal Idiot - Unreal Engine 4 Tutorial: How to tell your character is grounded

None of these work properly for me. I must be doing something wrong.
Regarding “is Moving on ground”, I made this and bound it on event tick, it never toggles the “AIR” print string. It’s always on the ground.

Regarding the line trace, I made this, inserted it in the same place on tick and it only returns “AIR”, no matter how I tune the Get actor up vector.

What am I doing wrong guys ?:confused:


And second: can you show us the blueprint logic of how you are lifting the character off the ground? Also a screenshot of the characters component heriarchy.

He is not lifted, he is falling, so it’s just gravity. (btw, the “is falling” function doesnt seem to work either (instead of the "is moving on Ground).

This is the component list:

The only thing with physics enables is the “Player_Cube”.
This is only a placeholder.

I deleted that branch, and connected it as you said (I think I had this done in the past too, but I was just trying things now). It shows AIR only at the beginning, because on start it is falling a few meters. Then it hits the ground, prints GROUND, and keeps printing only GROUND. When falling it doesnt print AIR again.

Uf :frowning:

I see here he’s falling but still leaving tire tracks or is it the perspective?

So it is working…I suggest you try on a level with simple ramps (triangles, boxes, planes) to test this out, then move to custom more complex terrain.

Its just the perspective, the tracks are a simple particle system and they keep spawning regardless if its in the air or not; those are not the issue (yet :smiley: )

Thought this might help: Landscape Collision Guide | Unreal Engine Documentation