Swapping relative velocities for 2 actors
So I have split-screen 2 player game I'm working on for a Game Jam where players can blast each other with a force that applies a velocity. (Using a sphereTraceForObjects).
My issue: I am trying to create a Swap mechanic using the sphereTrace that on hit, swaps the world locations and relative velocities of player 1 and player 2.
E.g. P1 blasts P2 -> P2 is launched into air relative to direction of blast -> P2 in mid-air hits P1 with a Swap -> P1 and P2 location and velocity Swap -> P1 is now being launched with P2's velocity.
I can attach some images of my blueprint so far later on today to help but any advice anyone has is greatly appreciated!
asked Jan 22 '19 at 01:45 PM in Blueprint Scripting
As for the basics, you're going to be using the Get Actor Location and the Set Actor Location nodes to swap your two players' locations. On the set location nodes, you'll want to set the Teleport parameter to true to ensure you don't cause any sweeping collisions as each player is transported from one place to the other.
You'll also need the Get Velocity node to get each pawn's velocities, which you will swap by using the Set Physics Linear Velocity node. (Note that the Set Physics Linear Velocity node requires a component reference, such as your pawn's mesh component; in other words, you can't just feed in an actor reference to that node.)
You might also want to consider disabling your pawns' collisions during the swap to prevent the pawns from momentarily colliding with each other when one is moved into the other's position. This might not be necessary, but it's something to think about if you start noticing weird behavior after the swap occurs.
Hopefully that's enough to get you started, but let me know if you could use some more tips!
answered Jan 22 '19 at 06:41 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here