#Could you by chance check out my coding
1 messages · Page 1 of 1 (latest)
correct
Have you setup any form of 2D collider?
Yup, the slimes have a Capsule Collider 2D and the walls have a Tilemap Collider 2D
The slimes also have a Rigidbody 2D
If it helps, here's a video of what I mean
ah ok your script randomzies a direction to go in and you use a transform update to move it there
yup
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
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
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
Is the physic material a component?
no, it gets added to the collider
you create one in the same way a normal material
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
It just adds a force when something touches it. Kind of like a conveyor belt
Ah okay
Aye, I did a bit of tinkering and changed my code a bit and it's almost better than perfect! Do you have any idea how I could make the slime go idle though in those few cases where it comes to a stop @granite river? it still seems to jump. https://paste.ofcode.org/xT45szApZEdgzw7VnaQU7t
(Ignore the slime on the left)
you can cast a ray from the current position to the final position. If it hits a wall, you can tell it to go to the point it hits on the wall, change a direction, etc
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)
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?
Instead of checking against a position, check it's magnitude. Do rigidbody.velocity.magnitude and compare it against something less-than 0.1f
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