Custom Collision Detection

Okay, I am trying to make my own character controller based completely on script with no help form unity's pre-built components. Right now to detect collision's I have a ray casting from the controller on each of the sides (front,back,left,right). That part is working fine but my problem is getting the object to stop when its going to go through an object. Well that's not exactly correct, I am getting the controller to stop by setting the speed variable to 0. The real problem is getting it to go again. What happens is the controller stops but there's no way to get away from the wall or object after a collision has occurred. So my question is what would be the best way to fix this problem.

By the way I am using unity script not c# just in case anyone decides to setup a code snippet.

Thanks in advance and sorry for the lengthy question.

Use Physics.Linecast?.
If nested within a while statement it should work. In english cause I am lazy.
While there is a collision if I move{
moveless;
}
else{
DO OTHER STUFF;
}

Linecasting only checks a certain distance. So as long as your speed is at zero it should not return a collision. Cheers.

What you are looking for is the Dot product.

You want to disable movement when the player is inside a wall, so

if(Vector3.Dot(velocity,hit.normal) < -0.1) velocity = Vector3.zero; //when you get better replace this with a custom-made collision function, which will nullify the component of the velocity towards the wall

It would be easier for you to use one raycast in the direction you are moving.

In order to do this you will have to use transform.forward for the direction of the raycast. If you really want to create a capable-of-working-in-any-situation collision system your knowledge of Vector3’s should be impeccable (you should eventually know the concepts of the Dot Product, Cross Product, Vector Projection, Vector Rejection, Vector Reflection).

For said raycast, look into this code will help:

var hit : RaycastHit;
var hit2 : RaycastHit;

if(Physics.Raycast(pos - Vector3.up*0.5,dir,hit,Mathf.Infinity,(1 << 0))
    && Physics.Raycast(pos - Vector3.up*0.5,-hit.normal,hit2,Mathf.Infinity, (1 << 0))
       && (hit.distance < radius + dist || hit2.distance < radius + dist))//find the normal below us and find how close it is
         {
         if(hit.distance > hit2.distance)
          {
          hit.distance = hit2.distance - radius;
          }
          else hit.distance -= radius;
         }
return hit;

(I call this IterationArray.)

It basically finds the first normal in the direction the direction of the velocity, then takes that normal and finds how close it is. You should optimize this even more by using some logic like this:

if(Physics.Check Capsule) //if there is something occupying the space, then do stuff, otherwise don't bother
    {
    if(IterationArray) //check if we are on a flat plane first
    else if(Physics.SphereCast) //check for a contour or corner of a mesh
    }

I’m currently making a parkour package that I’ll put up on the Unity Asset Server for free, so when I get there, I’ll try to inform you. The parkour package has a pre-collision system with a failsafe of the Unity3D collision system that prevents bad things from happening. In the OnCollisionStay field, a Debug.Log() is rarely called, meaning that the precollisions work most of the time (but definitely not all of the time).

Why are you using raycasting and not the actual collision detection provided via PhysX?

What do you do when you run into a wall? Either back up or turn you silly person.

dear god that sounds tricky so id recommend not using raycasts because they are expensive on processing but if you are determined to go that way

now this isnt accurate so you'll have to figure out the right numbers you could write it so if right raycast hits object, move player in the negative x if left move in positve x ir front move in negative z if back move in positve z

nothing dramatic just enough to push the player away from the object and get his raycast out of it at that rate you could even set it to apply damage if they are touched

but if you use colliders than you wont have to worry about any of this because well colliders collide and either depending on your preference will stop objects from passing through each other or not.