Collision for Anchored and Complex objects

To be honest I have absolutely zero clue on why this isn’t working but I’m making a game where you control this square and move him around the screen to avoid certain things and try to make it to the end without dying.
Pretty straight forward, however, I can’t for the life of me solve why no code I try will register what is overlapping the player. I’ve tried the :Touch() event even though it doesnt work with it because its anchored, I’ve tried the :PartsInRange() and Tried the sneaky way of using the touch event for it to work with anchored parts.

Yet to no avail, still doesn’t work.

So I’ll do my best to explain this. The character is moved frame by frame using the movement input from the player. The player is also Anchored so they do not fall into the infinite void. The parts colliding with him are animated objects part of bigger rigs.

I’m trying to get when the animated object is overlapped with the player to hurt him. I cannot however use something such as:

local playerHitbox = script.parent
local pX = playerHitbox.x
local pY = playerHitbox.y

-- check all parts in the workspace and see if they are in the range...
for i,v in ipairs(workspace) do
     if v.x + playerSize > pX and v.x - playerSize < pX then
          print("Collide")
     end
end

I cant use a code like this because I use custom meshes and this would only work for squares.
I’ve tried doing this in like 20 different ways and as much as I hate giving away my Roblox projects, at this point I’d be willing to to get this fixed.

Ok it got even weirder. It works unless I’m using that player as my controlled character. For instance, just dropping it in the workspace and letting nature, or well in this case the opposite of nature, take its course it’ll print everything.

This is more brainstorming than a solution.

I hear animated rigs, and I immediately lean towards animation markers. Is it good enough to check for “collisions” at certain points in the attack, or does it have to be every frame? If you only need to check on certain keyframes, you might be able to hard code an unsafe position to check.

As for collisions, I have a hard time with passive complex objects. I can’t imagine how hard a moving one would be. I approximate the shape with invisible simple objects. My “gate” has no collisions, but each side, and the gate itself has an impassible block to simulate a door. My stair meshes have collision blocks for each step. It looks like it works… :wink:

You might be able to do this with your “weapons,” adding a simple cube or sphere that follows the animation. It would be far easier to test one block than a whole animation.

Combined with the keyframe marker approach, you wouldn’t even need to animate the part. “At keyframe marker A, is player touching invisible part B?”

Basically, can you simplify the problem so that you are do very specific tests?

EDIT: also, if you are using skinned meshes, keep in mind the animation has no physics at all

1 Like

It does have to be every frame yes, as the entities move around the map with said animations. Also, yes. I’ve done everything to make this work and do have simple parts (not meshes) as the hitboxes. And I have simplified the project but its really odd. It seems to detect the touch events if I take the movement code out of the player, along with not cloning the player to make a new one.
Is it possible that cloning the player is what breaks it?

I’ve discovered you need to redefine all your player parts whenever a copy is made. So yes take a look at that

What do you mean redefine? I make sure the touch code doesn’t run till after the player is cloned if that’s what you mean.

If you’d be so kind to try and help me out with this a little more I can send you a project file over Email.

Any time you define a variable pointing to a part on the character, it only works for that instance of the character. References to HumanoidRootPart, Humanoid, etc, still point to the non-existent instance until you redefine them.

Yea, I can take a look at it.

Thank you so much! If you dont mind me sending it by email, I’d rather not give the majority of my high school free time code away to the public.

I’m trying to duplicate the player at the moment to test more about what could be the issue. Keep in mind the parts are anchored so no normal touch events work because of the way Roblox is coded.

The issue is something with both the object trying to check for collision is local along with the object that is supposed to collide with it is also being a local object. Therefore not working either way.