Dynamically scale a hitbox between 2 irregularly moving points.

hello! so I’m working on developing a project that has a lot of obscure things in it. I’ve been able to figure a lot of it out and get it all mostly working, but I m stumped on this one.

I have a hitbox within an actor, and I need to scale this hitbox between 2 points within the actor. those 2 points will change irregularly and I haven’t been able to figure out how to mathematically get it working.

I’m only adjusting the X axis, the Z and Y axis are staying uniform.

is there a way to snap it to two coordinates on each side instead of scaling from the middle?

It would be like this :innocent:

In my case, the actor (or it could also be a collision volume) was located like this, having the scene root on it’s bottom corner that’s on the negative side of each axis:

Hope this helps! :blush:

So I thought this was working but it turns out its not. the hitbox is inside an actor with other things that should not be transforming the same, I need JUST the hitbox to be transforming. without anything else in the actor. I cannot separate actors either.

the pivot point is stuck in the dead center of the hit box and as far as I can tell there is no way to move the pivot of a single object inside an actor.

That’s a pretty big claim since it is working for me :rofl: I just couldn’t record a showcase because it stops when I exit the game.

Let’s go over the issues you’re having.

You can adjust the pivot point by using the middle click of the mouse and dragging it to your liking. When you’re done, don’t click off the actor as it would reset your adjustment. Instead, right click on the actor, navigate to the Pivot section and choose the Set as Pivot Offset option. Now, this is how you adjust the pivot points. That white sphere you see in the actor blueprint is not the pivot. The pivot would be the scene root there, which you can’t adjust. What you should do is locating the mesh / collision box / anything you want accordingly.

Like I mentioned here:

The usage of Set Actor Location & Scale nodes were just for demonstration purposes. You can replace them with the box collision versions. :blush:

Good for you! I clearly have not articulated what I’m trying to achieve here.

everything is done all within one actor, there is nothing happening outside the actor. If I change the pivot point out side the actor, nothing of any significance will happen since the actor, and most of its components will never move.

everywhere i have seen online says this cannot be done within the actor it self. only to the entire actor, I have infact not been able to get it working on components

I want to change this one component from within the actor based on 2 invisible points inside the actor. the scaling needs to stay relative to the root, the root needs to stay center for the sake of the other things in the actor. I’m sure I’m failing to articulate what I’m actually trying to achieve here but its very, very different from most things.

Let me try and rephrase:

I have 2 mathematical expressions that have 4 different variable inputs that output the “close” and “far” points of the collision box component. I need to keep the collision box in-between those two points of near and far. all of this must be done inside an actor whare the root and other components cannot be affected.

No I get your objective. I think there’s a confusion going on.

I didn’t suggest you to do that. I just explained how to adjust pivot points. It’s not that it cannot be done in the actor blueprint, like I explained earlier, the pivot would be the scene root there and not the white sphere that’s always at the center of your selections.

As I mentioned here:

I chose to place the component(s) like this to keep the code simple. You can also make it work with different placements, but I recommend placing this way.


What You Should Do Now

You should locate the mesh, the collision box and everything else accordingly.

If that causes issues on other parts of your project, for instance setting the world location of the actor, you can simply adjust the location before setting it to have the actor’s center align with the desired location.

And again, to only affect the box collision, you can use the Set World Location and Set Scale 3D nodes for the box collision like I explained earlier. We’ve already established that the manipulation of the actor was just for demonstration purposes in my initial post.

Either there is some variable in my equation that is outputting the coordinates for my near and far point to not work with your math, or i have quite simply continued to fail my explanation of what this project is. thanks for trying, however this is not the solution and I will continue to try and find one. if I do find one I will update this thread.

You can just cast sphere traces on those 2 points and see what’s going on. If the component’s rotation is wrong, just check the viewport and see if your collision box’s placement matches with the mesh in my screenshot.

Additionally, let me explain how to math works so you can understand what we’re doing here. We’re just locating the component on one of the points, then subtracting the other point from that one to get a vector that doesn’t define any location but shows the direction of the second point according to the first one with the magnitude, and setting it to the scale value of the component. The reason where the component is around the scene root matters is because the scale value sets the other point of the the space diagonal according to the world location.

I’ll send you the exact code for your case later. Until then, see if you can make sense of my explanations.


Hey there @teradore, I just got on my PC. Here’s the exact code for the collision component, it’s a bit different:

And here’s the result:

As you can see, the collision volume moves independently of the actor and it adjusts itself to the points. This was the objective right?

Hope this helps! :innocent: