Moving NPC on client side

Hello! My goal is to get an npc to dash forward, but only for one client. I tried adding a linear velocity to the npc client sided, but it doesnt work, and i think its because the client needs network ownership to apply physics to the npc, but since I only want the dash to be seen on one client, i cant change the network ownership. Is there a way to get the NPC to do this?

Edit: For context, i’m trying make a turn based battle, and on the enemy’s turn the npc will attack all players in battle. However, it is done on the client side, so the attack will look different between players. This specific npc is supposed to dash towards the client, so on different clients the npc will dash to different locations, based on the client’s position. Hope this context helps :slight_smile:

2 Likes

You can use :ApplyImpulse() method of basepart (part/meshpart etc)
The bigger vector = the higher power
Example:

root:ApplyImpulse(root.CFrame.LookVector*100--[[Multiplying Vector3 to give more force]])

does it work if a client uses applyimpulse on an npc without having network ownership?

this method is not tied dirrectly to server nor client.
You can call it on client.
Aslong as you or server (nil) owns network of object you should be fine. :handshake:

i tried it and it still has the same problem, where the npc wouldnt move. i think since its physics related the client needs to have network ownership

You should try setting network ownership of NPC to nil :thinking:

that didnt work either. though… i thought setting network ownership of the npc to nil will make the server have network ownership of the npc, which the server already has. i think the client needs to have network ownership to do anything physics related (like applyimpulse) to the npc.

when i tried setting the network ownership to the player everything works fine so i think network ownership is the issue

1 Like

Yes, you are calling it on the client, the client needs ownership to apply physics.

Have you considered generating the NPC on the client? The physics will be controlled by the client and will only be seen for that client.

You can make it far simplier:
Make humanoid rootpart on a client and replace it.
Giving you isntant control over assembly while keeping rest synced with server.

1 Like

This is difficult with a server-side NPC. Your best bet might be to make the NPC on the client entirely, or make a clone of the NPC for the sakes of effects and animations like this (either when combat starts, or just before the dash effect).
If the client doesn’t have network ownership of the NPC, the server will keep updating it with its actual position, and desync will likely happen, which you don’t want.

Thanks for sharing some solutions, yeah I figured that the best solution was just to clone the enemy on the client side and hide the server side enemy

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.