- Home /
No specific question/Discussion Topic
Character mouvement and collisions in arbitrary angled surface
I wonder what you guy would do for a cheap replacement of character controller in unity. I try a bunch of implementation and they don't work at all, what I'm doing wrong?
I'm trying to make a game with megadrive's sonic pinball physics, think (technically) about mario galaxy meet tony hawk with sonic's high speed. Currently I use a simple raytracing, but I'm looking to listen collision around the sphere collider.
In my case i tried:
Rigidbody turn the game in a slide show, Intel atom n455 for the win (actually I like the limitation so it can run on most machine).
Kinetic body don't collide with scenery (don't listen collision).
Character controller don't rotate.
Sweeptest() and SweepTestAll() but walls and inward curve fails dramatically. + it does not work with the flash preview of unity 3.x
I want to be able to move the character according to tangent of arbitrary complex volumes. For example, taking slope change higher than 90° and leave the case handling with special case code (for example stopping at a wall or falling down a cliff)
What should I do to meet the requirement with good performance?
Currently my code is this one, with sweeptest() which doesn't work:
private void UpdateSurfacePosition()
{
Ray//origine, direction
ground_check_ray = new Ray( gameObject.transform.position, -gameObject.transform.up);// * (Momentum.magnitude + 1));
RaycastHit
raycast_result;
Rigidbody
rigid_body = gameObject.rigidbody;
rigid_body.detectCollisions = false;
rigid_body.isKinematic = true;
bool onGround;// =
//Physics.Raycast( ground_check_ray, out raycast_result );//ray, hit
//rigid_body.SweepTest(-gameObject.transform.up, out raycast_result);//direction, hit, distance
raycast_result = new RaycastHit();
RaycastHit[] contacts = rigid_body.SweepTestAll(-gameObject.transform.up);
rigid_body.SweepTest(-gameObject.transform.up, out raycast_result);
if (contacts.Length > 0)
{
onGround = true;
int i=0; while (i != contacts.Length)
{
raycast_result.normal += contacts[i].normal;
i++;
}
raycast_result.normal = raycast_result.normal.normalized;
}
else
{
onGround = false;
}
debug1 = "Normal > " + raycast_result.normal.ToString()
+ " Position > "+ raycast_result.point.ToString()
//+" transform > "+ raycast_result.transform.name.ToString()
+ " Contact > " + contacts.Length
;
if ( onGround )
{
Vector3
next_position;
//UpdateOrientation( gameObject.transform.forward, raycast_result.normal );
UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );
next_position = GetNextPosition( raycast_result.point );
rigid_body.MovePosition( next_position );
//ground_direction = raycast_result.normal;
}
else//onAir
{
//if forward close to dot.Y = abs(1) choose -up if 1 and up if -1
UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );
}
}
I don't see a question here. Plus this looks more like a discussion that should be handled on the Unity Forums. Unity Answers is structured to answer a specific technical questions.
well my code doesn't work, I lost the first post i apperently I lost the question gasp
O$$anonymous$$AY it's just that unity is shit for any complex gameplay http://forum.unity3d.com/threads/142375-The-limitations-of-the-physics-API-and-creating-a-character-controller