Distance to the part

  1. What do you want to achieve? It is necessary to make sure that the zombie does not ‘enter’ the part, but stands next to it and attacks it

  2. What is the issue? Video

  3. What solutions have you tried so far? I checked other forums

--not all, but main part i think
if (target.Position - script.Parent.HumanoidRootPart.Position).Magnitude > 14 then
   hum:MoveTo(v.Position)
end

How do I make sure that a zombie does not enter the part, but stands next to it? I tried to track the distance, but because it’s a rectangle, it has a different distance on each side.
image
I also tried to place attachments around, but it was laggy (zombie go to the one, then go to the second, but shouldn’t)
(I used translator, so I can have mistakes in my text)

If you have questions you can ask me

3 Likes

Hey @Sasha899_2017

Have you ever tried to write the position of something in code before?
like

local Direction = (target.Position - script.Parent.HumanoidRootPart.Position).unit
2 Likes

yes, i tried, i put this bc this is script for test, not main

1 Like

The easiest way is to put another part that is slightly larger than the main part to check if the zombie (you can use the zombie’s humanoid root part) touched that another part and if it did then: stop it from moving

1 Like

I may be wrong, but can you try something like this locally and then try to set up an equation?

so first create a target so that the rectangle you are mentioned about here
then calculate the direction in advance as I said
then write a part to pre-calculate the desired ranges
like this : target.Position - direction * num
then move the npc this direction

2 Likes

If i understand you in the correct way, you are talking about ‘Touched’ event?

Yea, the Touched event, I am talking about that one

1 Like

Have you tried passing basepart to the :MoveTo? :MoveTo(Position,Part)

No.
Is it really can change something?

I have’t really tested it before but this might force the character to stop at part means it might stop it outside of the part.

I think he meant how to check when the zombie should stop (check when the zombie should stop when close to the part), not how to stop the zombie from moving i think

You are correct.
I tried to connect Touched, i think it really can work, but zombie can leave this part, how i can track it?

Can you clarify about what you want to do?

you could try moving the zombie to the part while firing a raycast 1 stud in front of it and when the cast hits the part stop the zombie

1 Like

Yes, You said that I could use the Touched function, I tried it and it would really work, but one thing is, my zombie leaves the part when a player is next to a zombie. And then how can I tell when a zombie is in the part and when it’s not?

If it’s still not clear, I can send you a video.

sure, you can send me a video, it can help alot

Here is my video : https://youtu.be/YQyzdWS4hJc
Here you can see that zombie can leave my part and script wont write anything again.
Again, how i can modify it? bc if i stop the zombie, it wont go to the player.

Umm, I need you to clarify what you meant by “script wont write anything again”?

basePart:GetClosestPointOnSurface(zombie.Position) should help. This’ll tell you how far the closest point on the part is.

1 Like

I mean that script wrote “zombie” in the console, but when zombie left the part it didnt write ‘zombie’ again