#Enemy AI

1 messages ยท Page 1 of 1 (latest)

spare fiber
#

@rocky crest So it won't really move unless I set the speed to 4000 but it moves way faster in the air than on the ground

rocky crest
#

speed? I thought you apply a force...

#

Force = mass * acceleration

#

so, if you apply the same force, but with no friction, is SHOULD accelerate faster

spare fiber
#

I'm using a custom A Star script made by someone in a YouTube tutorial

rocky crest
#

guess you better show me that relation...

spare fiber
#

But I'm starting to thing they didn't do a very good job ๐Ÿ˜‚

spare fiber
rocky crest
#

how you compute force using "speed"

spare fiber
#

I think that's wrong, though

#

Shouldn't it be fixedDeltaTime?

rocky crest
#

no deltaTime works.. I just think the name "speed" is inaccurate for what that is.

#

actually,,, I don't think you force should be based on deltaTime, at all.. that is accounted for when you Apply the Force to the object

#

it does somthing like.... velocity += acceleration * deltaTime inside there.

#

(where acceleration depends upon the force you apply, the friction it experiences and the mass of the object)

spare fiber
rocky crest
#

yes. I'd also rename speed to force, so you dont get confused.

spare fiber
#

Okay, now I don't have that issue

#

However, I have another issue now

#

The speed of the enemy fluctuates in a weird way

#

Like it basically looks like its rubber-banding

rocky crest
#

like you push it, it starts to slide then slows down, then you push it again?

spare fiber
#

I'll record it real quick

rocky crest
#

cool. are you applying the force in Update? are there any conditions around it? If so, I'd sugest a debug.log("pushing") cvommand when you apply the force so you can make sure it's being applied every update, rather than only occasionally

spare fiber
spare fiber
rocky crest
#

ok, still- I'd try the debug log and confirm it happens "often" rather than "occasionally"

#

"it" being the application of force

spare fiber
#

It looks like it is

#

I'll go ahead and give you the whole script because I feel like that will create a lot less confusion and questions

rocky crest
#

rb.AddRelativeForce(force); never use this one.. what do you get with plain ol' AddForce

spare fiber
#

It still kinda speeds up when you jump over it, but not to the same degree

rocky crest
#

this makes sense.. there is no friction when it's NOT touching the surface

#

perhaps, you dont want to apply forces if it's in the air? Then it will not change veloicty at all (regardless of input)

#

this is how real world works- but many video games DO let you control yourself in the air

spare fiber
#

The enemy also seems to get stuck on ledges

rocky crest
spare fiber
rocky crest
#

no, if it works thats fine.

#

just need to use that "isTouchingASurface" result in an if statement around your applyForce command. so it only applies the force when it IS touching a surface.

spare fiber
#

Okay, i figured out the issue

#

The enemy speed seems to increase as it gets closer to the player

rocky crest
#

got some stuff to do for a bit- I'll ping ya later to check in

rocky crest
#

heya, make any progress?

spare fiber
#

Kinda

#

I now need help making it slow down as it reaches the player