How to create a flying NPC?

just animate it bro or do mean something else

1 Like

I mean making it move towards the target with a BodyPosition, not animate it.

2 Likes

What are the current problems you have with BodyPosition? Is it that you want the force to be constant but BodyPosition is applying an unconstant force?

1 Like

Yeah, I mean look at this gif:
https://gyazo.com/1354a56f8612c8897b9c9b0550160e0c
You can clearly see how inconsistent the speed of the dummy is. The BodyPosition has a MaxForce of 1500,10000,1500, a power of 10000 and a dampering of 1250. Changing the MaxForce will only change the max speed of the dummy, which is useless if I wanna keep a constant speed, not based on the target’s position. If you didn’t understand something ask me, and thanks for the answer :slightly_smiling_face:

1 Like

BodyPosition, the dampening property is preventing your NPC to move towards the target at constant speed, hence decelerating it as it approaches the target to prevent inertia. Try this: lower the dampening and increase the power

These images are from roblox’s api reference section

I tried that, and yeah the speed changes but I don’t see anything constant. Look at this:
https://gyazo.com/8fd09aac112ffee7a0360def7c9051d6
See how at the start the NPC was super slow, while the speed changes everytime I move my character? I’m not quite sure if it’s based on the character’s distance from the NPC, but it’s very annoying. I could use them this way but it would’ve been better if they had a constant speed.

I know you are not looking for a bee

But it seems to me that it’s close to the thing you want to do

Sorry if my post is off topic

1 Like

No no, it’s not off-topic, and actually it’s extremely similar to what I’d like to achieve. Did you make this? If so what method did you use? I don’t want your full script, just the BodyPosition part to understand it, if possible obviously.

In the case of the bee chasing the player

bodyPosition.Position = HumanoidRootPart.Position

That’s it? I use the same method and the speed is inconsistent (as shown in the previous GIFs). Guess I’ll have to play with MaxForce, Power and Dampering more? Thanks anyways for the answer.

I’m sorry, the translation is not clear, I don’t speak English

Use BodyPosition to set the height

Use BodyGyro to adjust its orientation to the body

Use BodyVelocity to adjust body velocity

It looks like you are using another method

Change the height of the bee and set it to the level of the player’s height in case of Follow

bodyPosition.Position = HumanoidRootPart.Position

I would avoid using constraints for this as it might end up wobbling around unnaturally. Imagine you set its position after it gained a lot of momentum. It will end up rubberbanding around the target position until its velocity reaches 0,0,0.

A simple CFrame lerp between the current position and the target position based on a time delta would be much more effective in your situation.

But if you want to avoid writing collision physics, you could go with constraints or a velocity system or with force impulses; however, make sure you apply a lot of limits to avoid the said issue.

If you want to continue with constraints, you should use a single large block for physics and collision and set all other parts’ Massless to true and CanCollide to false. Keep the X and Z rotation at 0 degrees at all times and use VectorForces to move it around. The general formula for the total force should be:

TotalForce = GravityConstant*Mass - Velocity*AirDragConstant/TimeDelta + DesiredDirection*MovementConstant

If you’re looking for consistent speed, set the MaxForce property to inf and play around with the dampening value. Here’s a GIF: https://gyazo.com/eb242ad2e22dfcfa777f7cf791711a95

Set the Value of Dampening close to 0
Since you only want to use Body.Position, Lower dampening will prevent NPC to decelerate depending on its distance from target

The best option would be to manipulate its CFrame while playing an animation to make it fly. This way there would be no errors with miscalculated velocity or any of the glitchy Roblox physics either.

NPC flies over the player and moves with him in the same direction

1 Like

Hello everyone, I managed to find a really easy solution that I didn’t even think about. This doesn’t involve MaxForce, Dampering or any other property of bodyposition. What I’ve done is an actually very simple yet effective solution: in the Humanoid, there’s a property called “WalkToPart”. If you set this to the HumanoidRootPart of a player, the NPC will go towards that point, and the speed is constant. Why? Cause it uses the WalkSpeed property of the Humanoid! So, to clear it up:

  1. Add a BodyPosition to the NPC’s PrimaryPart to keep it in the air, and set the BodyPosition.Position to the current NPC’s PrimaryPart position;
  2. Adjust ONLY the Y axis of the MaxForce property (of the BodyPosition);
  3. Change the WalkSpeed of the Humanoid based on the speed you want the NPC to have;
  4. Keep setting the Humanoid.WalkToPoint and BodyPosition.Position to the target’s HumanoidRootPart (or PrimaryPart) position! I also recommend adding a Vector3.new(0,3,0) or higher (based on the NPC’s size), since if you don’t add that the NPC risks glitching under ground.
    Result (the Humanoid’s walkspeed is set to 16):
    https://gyazo.com/6434446826f82016c6965dee3a8ae9c2

I hope this was and will be helpful for others!

6 Likes

Hi AndroidBoyz,

Could you possibly share the code that you used for this effect? Any screen shots would be helpful.

Thanks,
Leif_aw

This is exactly what I’d like to achieve. Can you share you code please?

I’m sorry I can’t share the code but I can only tell you what you have to use to make the ghost follow the player

Use BodyPosition to set the height

Use BodyGyro to adjust its orientation to the body

Use BodyVelocity to adjust body velocity

1 Like