I am wondering if it is possible to create a vector/plane from the direction of motion?

Basically, I am using “slice procedural mesh” to cut through materials with a “lightsaber” but I can never get the slicing plane to be at the right angle. Since it’s a lightsaber and not a sword, most of my animations don’t have the lightsaber swing following one plane like you would with a sword, because it doesn’t have to, it’s omnidirectional.

Because of this, if I just try to attach a plane to the blade of the saber, the angle of the slice is hardly ever rotated correctly. Currently, I just have the slice cutting a random angle between -15 and 15 degrees from horizontal to add some variation.

I figured if I could track the motion of the lightsaber and make a plane from it that could make a very accurate slice angle but I have no idea how I would do that or if it’s even possible. I am very new to programming and game design so any help/ideas would be appreciated.

1 Like

I’m just speculating here, but the math should work. Try this:

  1. Add two socket to the saber mesh, one at the tip of the saber, the other somewhere on the blade.
  2. Get the location of one tip socket in two different frames during the attack animation. Subtract one from the other, and you get one vector of the plane.
  3. Subtract location of one socket from location of the other socket, and that’s the second vector you’re looking for.
  4. Now I’m not sure if you can create a plane just from these two vectors, but there’s a node that creates a plane from the normal vector: [Make Plane From Point And Normal]; to get the normal you need, get the [Cross Product] of the first two vectors you have. The point should be the location of either socket. That’s the plane you’re looking for.

P.S. There’s a node called [Make Plane] but it takes in four floats and I have no idea how to use it.

2 Likes

Thanks for the help, I definitely think this would work except for the fact that I would need the vectors to be drawn in real-time so pulling the locations from the attack animation I don’t think would work. My character will be spinning and swinging all over the place so even having one set angle for every animation probably still wouldn’t work so great. Are you aware of if it would be possible to pull the location of the socket at two points in time rather than at two different frames in an animation? My idea was that On Begin Overlap a point would be drawn and then On End Overlap another point would be drawn and I could somehow get a Y-Z vector from that. Then, for the X direction of the plane, I would just set it to always be facing away/towards the player… In my head, it seems like this would work great I just don’t know how, or if it’s even possible, to do that in Unreal.

1 Like

Sure, why not. Still same, save two locations of the sabre tip socket, one on BeginOverlap, one on EndOverlap. subtract one from the other, and that’s your first vector; and Sabre tip location minus player location is the second vector; and then do the same as I described before.

2 Likes

Holy ■■■■, thank you so much! after about 8 hours of trying to multiply vectors I finally did it. Would have probably saved about 6 hours if I didn’t assume that the multiply vector command did cross product. Turns out there is a separate cross-product command (duh). Basically what I did if anyone comes across this in the future is I made a vector from the tip of the blade to the hilt, then I made a vector from when the blade enters the object to when it leaves. Then I just cross multiplied the two vectors and plugged it into the plane normal for the slice procedural mesh command.

1 Like

Nice! Glad you’ve found your solution.

1 Like