#Enemy AI
1 messages ยท Page 1 of 1 (latest)
@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
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
The force applied is based on the speed
I'm using a custom A Star script made by someone in a YouTube tutorial
guess you better show me that relation...
But I'm starting to thing they didn't do a very good job ๐
The force variable or the whole script?
how you compute force using "speed"
Vector2 force = speed * Time.deltaTime * direction;
I think that's wrong, though
Shouldn't it be fixedDeltaTime?
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)
So just do speed * direction?
yes. I'd also rename speed to force, so you dont get confused.
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
like you push it, it starts to slide then slows down, then you push it again?
Yeah, kinda
I'll record it real quick
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
It's a function called in FixedUpdate
ok, still- I'd try the debug log and confirm it happens "often" rather than "occasionally"
"it" being the application of force
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
rb.AddRelativeForce(force); never use this one.. what do you get with plain ol' AddForce
It still kinda speeds up when you jump over it, but not to the same degree
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
Yeah, I don't want it to apply force when in the air
The enemy also seems to get stuck on ledges
ok, so do you have a way to detect if it's touching a surface or not? (I'd check colliders e.g. https://docs.unity3d.com/ScriptReference/Collider.OnCollisionExit.html)
I'm currently using CapsuleCast but I can switch to collider detection
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.
Okay, i figured out the issue
The enemy speed seems to increase as it gets closer to the player
got some stuff to do for a bit- I'll ping ya later to check in
heya, make any progress?