player try to go into the ground to reach raycast hit
Hi. I am using RayCast to tell the player where to go to using my mouse. So what i think that happens is that the middle of my character (which is a ball) is trying to reach the ground and because it can't it does like a alittle jumping over and over. Also it's starting to fall through the ground at some point. No errors are generated. I have a rigidBody and a sphere collieder on my character. I have a collider/ mesh (don't know what it is called) on my terrain.
If you want to view a script please ask and i will post it here. Please help me. Ethan
Answer by dhore · Apr 13, 2016 at 11:06 PM
The position of a spherical object, by default, is located in the direct centre of the sphere. Therefore you're telling the centre of the sphere to go to a point on the ground ... which it can't get to because half of the sphere is under that point. So all you need to do is add half of the sphere collider's Y height to the position before telling it to go there, like so:
Vector3 destination;
// calculate destination using raycasts here
destination.y += playerSphere.GetComponent<Collider>().bounds.extents.y;
// now tell the player to go to the destination
Thank you. it makes if better but it is still a little funky. Is there anything else i can do to make it jump a little less? Ethan EDIT: Its jumping may not have been the problem because it sank into the ground again.
It did help but in some places the player still sinks into the ground spontaneously. I think it's something with my multiplayer. Thank you @dhore ethan