x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to write a smooth crouching script in blueprint?

I work on the community game Trillek, and we have been unable to figure out how to get the player to crouch other than using the default crouch method and snapping the camera to the crouch position. If someone could point us in the right direction to setting up a lerp for the crouch function, it would be greatly appreciated.

Product Version: Not Selected
Tags:
more ▼

asked Aug 21 '14 at 05:47 AM in Blueprint Scripting

avatar image

elpresidenteffg
11 5 6 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi elpresidenteffg,

Here is the solution that I came up with for smooth crouching. I am using the First Person Template. If you are using the 3rd Person Template it will require some additional steps to add the crouching animations in.

  • Create a variable to hold the CameraLocation and set it in the construction script or OnBeginPlay in the Event Graph.

alt text

  • Add an InputAction for crouching (mine is LeftShift).

  • Create a variable for 'IsCrouching?' This will help if you decide to add in a sprint or something at a later date.

alt text

more ▼

answered Sep 04 '14 at 09:18 PM

avatar image

TJ V ♦♦ STAFF
41k 1009 183 494

avatar image TJ V ♦♦ STAFF Sep 04 '14 at 09:19 PM
  • And here is the setup for the inside of the Timeline.

alt text

I hope this help you get on the right track. If you have any questions please feel free to ask.

TJ

avatar image Kevinatorn Oct 15 '14 at 07:02 PM

Hello Sir, just wanna mention, when i try to do this, my character becomes a little bit taller, even though i've tried to tweak the numbers. I've done it the exact way as it's shown here without changing the numbers. Any idea what could be wrong? -EDIT- Just saw that i posted the comment on the wrong picture, i'm talking about the whole blueprint script.

avatar image TJ V ♦♦ STAFF Oct 15 '14 at 08:59 PM

Hi Kevin,

Could you post some screenshots of your event graph and timeline?

avatar image Kevinatorn Oct 15 '14 at 09:27 PM

Here's the event graph

print1.png (335.3 kB)
avatar image Kevinatorn Oct 15 '14 at 09:28 PM

Here's the timeline

[1]: /storage/temp/18042-print2.png

print2.png (159.6 kB)
avatar image TJ V ♦♦ STAFF Oct 15 '14 at 09:42 PM

On your Timline, the starting point is set below zero. Try setting it to 0, 0 and see if that fixes it.

avatar image Kevinatorn Oct 15 '14 at 09:44 PM

It worked, that was so sloppy of me hehe, i'm still new to this though. Thanks

avatar image TJ V ♦♦ STAFF Oct 15 '14 at 09:46 PM

No problem! It happens. I'm glad it's working now. :)

avatar image spaid Nov 01 '14 at 06:45 AM

Hi, I tried this and it works how I wanted it to, except when I stand up while under something the character just stands and clips through the scenery, getting stuck. Have I missed something, or would this need additional checks to avoid?

avatar image TJ V ♦♦ STAFF Nov 03 '14 at 03:06 PM

Hi spaid,

I've been meaning to post back here with an update. Shortly after making this mechanic I had to overcome this same hurdle. Here is the solution that I came up with.

  • Create a Line Trace for Objects that traces above the players head by a set amount. I have it checking on press and release.

  • If it hits an object (mine is set for PhysicsBody & WorldStatic, which is set in the EObject Type variable) it won't allow the player to stand.

  • I added an optional IsCrouching? variable that is set on Press & Release (this is done for a Sprinting mechanic I plan to have later).

alt text

alt text

You will notice that if you are crouched and walk out from under something you will not automatically stand up, you will need to tap crouch again to stand. This is because the Line Trace only checks on Press and Release. You could change it to check on a looped Timeline or a TickEvent using Delta Time and change this.

If you have any questions just let me know.

Cheers,

TJ

avatar image spaid Nov 03 '14 at 11:11 PM

Thanks TJ, this is working nicely. Though I did need to change it to a sphere trace to stop clipping right at the edge of overhangs.

avatar image Blue669 Jan 09 '15 at 05:02 PM

I was following all your steps and it works perfectly. Now I'm trying to convert this BP to make it work in multiplayer. The crouching mechanic works fine for the server and client, but as soon as a client goes into crouch, the camera starts stuttering up and down heavily. I've already tried several attempts to fix it, but I'm stumped. I would be so glad if anyone could take a look at this.

Here is my (slightly changed) BP: alt text

avatar image Tk-14- Dec 29 '15 at 09:11 PM

Did you fixed it?

avatar image CitéNoir Oct 15 '16 at 08:45 AM

@TJ Ballard / @spaid
As spaid said, using a line trace can clip you into objects, when you uncrouch right at the edge. I tried his sphere trace and it works better. but I'm still "able" to clip into objects at the edge, but only when I'm moving. so when I'm crouching towards an object and uncrouch while still moving I sometimes manage to clip into the object. I think it's because the trace doesn't hit anything when I hit uncrouch but during the crouch transition my location changes, because I'm still moving a few inches. So I kinda understand the problem, but I have no idea how to solve it. Just started with UE last week. Could you guys help me out? Thanks in advance.

uncrouchclip.jpg (384.9 kB)
avatar image CitéNoir Oct 19 '16 at 12:16 AM

@TJ Ballard / @spaid
still haven't figured out a way to get rid of the possibility to clip into objects. tried to play around with the radius of the trace. but if i set it too high, i'm pretty unlikely to clip into the edge of an object above me, but i also can't uncrouch anymore when i'm standing right next to a wall without anything above me, which is not wanted. here's my setup..

alt text

any idea, how to solve this?

uncrouchclip.jpg (384.9 kB)
avatar image elpresidenteffg Sep 29 '14 at 12:32 AM

Thanks, this is great!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

hi, I was looking for the smooth crouch implementation and found this helpful. Also I think i fixed the clipping issues and also uncrouhing when under the obstacles. Here are screenshots. Hope this would be helpful. It uses 2 Boolean variables and Custom Events.

alt text alt text alt text alt text

1.png (89.2 kB)
2.png (175.5 kB)
3.png (36.5 kB)
4.png (149.9 kB)
more ▼

answered May 05 '18 at 01:00 PM

avatar image

karti047
5 3 4

avatar image djrclement Jul 09 '19 at 08:43 PM

Hello! This works really well, except for the fact that the character goes through the ground while I am crouched. I am using the third person template. Any idea on how to fix this ?

avatar image karti047 Jul 10 '19 at 03:41 AM

Try setting the mesh position manually during crouch so it remains on the ground. What i mean is setting z position which refers to up axis. I don't know if it's gonna work correctly.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question