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"

Add discrete movement to Pawn

I want to move a simple Pawn object to fall from the sky upon being spawned but instead of simply crushing to floor it has to move on the Y Axis. This wouldn't be such a big problem if I made it move continuously as one would do with a Character object but I want it to use a discrete movement. What I mean is that it should move the same way the Tetris pieces do when they fall from the top of the grid: after X seconds, they drop down by Y centimeters and so on until they touch the floor.

Product Version: UE 4.14
Tags:
more ▼

asked Mar 02 '17 at 12:11 PM in C++ Programming

avatar image

kn0bbulo
19 2 3 3

avatar image VizualTek Mar 02 '17 at 12:20 PM

If you don't mind that your pawn/character kind of "jumps" to the new position you can use the AddLocalOffset/AddWorldOffset of your pawn/character. You can bind that to a buttonpress so you can kind of fall 50 units if you press one button and fall 100 units if you press an other button. If you don't want your pawn/character to jump, you could use some interpolation, so it travels smooth to the desired location.

avatar image kn0bbulo Mar 02 '17 at 12:23 PM

I need the "jump" on every tick so this is perfect. Thanks a lot

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

you could do something like this:

 APawn* pawn;
 FVector newLocation;
 FHitResult hit;
 pawn->SetActorLocation(newLocation, true, &hit, ETeleportType::TeleportPhysics);

this will Move the Actor to the new Location in one frame, without affecting its physics velocity. It will also sweep, which means it will detect any object between it and its target position and stop if it hits something (the ground for example).

Check out the documentation page for more details:

You might also want to check out this page, which shows exactly how you can move a physics object and what teleporting and sweeping actually does in a visual way.

The only thing left to do is to actually calculate the new position. You might want to store a custom calculated veloctiy on your pawn, so you can calculate your new position each frame. The rest is simple algebra.

more ▼

answered Mar 02 '17 at 12:28 PM

avatar image

pulp_user
1.2k 45 29 58

avatar image pulp_user Mar 02 '17 at 12:30 PM

This solution is a bit more heavy weight, than the comment above, but it is also more powerfull.

(comments are locked)
10|2000 characters needed characters left
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