#Could you by chance check out my coding

1 messages · Page 1 of 1 (latest)

granite river
#

So slimes are not colliding with anything when set to kinematic?

swift jolt
#

correct

granite river
#

Have you setup any form of 2D collider?

swift jolt
#

Yup, the slimes have a Capsule Collider 2D and the walls have a Tilemap Collider 2D

#

The slimes also have a Rigidbody 2D

swift jolt
granite river
#

ah ok your script randomzies a direction to go in and you use a transform update to move it there

swift jolt
#

yup

granite river
#

setting the transform position overrides any physics calculations when the body is set to kinematic

#

what you need to do is use the rigidbody to move the slime instead

#

and have the rigidbody not be kinematic

swift jolt
#

Is there a way to do that without using velocity? as I find the slime moves a bit too quick even after I've toned down the speed and also never goes into his idle animation because he's technically always moving

granite river
#

yes, you use the supplied force methods. like AddForce

#

make sure to have a physics material attached or the slimes will be too slippery

#

Also, any and all physics calculations need to be done in FixedUpdate

swift jolt
#

Is the physic material a component?

granite river
#

no, it gets added to the collider

#

you create one in the same way a normal material

swift jolt
#

Quick question, would a surface effector be just as viable?

#

added it on accident, but I'm quite liking the effect it has on the slime so far

granite river
#

It just adds a force when something touches it. Kind of like a conveyor belt

swift jolt
#

Ah okay

#

(Ignore the slime on the left)

granite river
#

if the ray is just thin enough to cast between like cracks, you can cast multiple rays, or use a collider stepping algorithm to check for path collisions (best results, but a bit slower)

swift jolt
#

ah okay

#

quick question though

#

when it stands still it should've swapped it it's idle animation and I believe the part of the code responsible for that was

if ((Vector2)transform.position != pos)
        {
            rb.MovePosition(Vector2.MoveTowards(transform.position, pos, speed * Time.deltaTime));
            animator.SetBool("isMoving", true);
        }
        else
            animator.SetBool("isMoving", false);
#

except despite not moving it never went to it's idle animation, so was position always active? and if so, is there a work around so that he can properly go into his idle animation when still?

granite river
#

Never do a comparison against two vectors, as they almost always have a micro variation that causes bugs

#

And if you want to compare a target position to it's current position, use Vector3.Distance and check for anything under 0.1f or more