• Advertisement
Sign in to follow this  

Collision for tangential movement in unity

This topic is 1675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wonder what you guy would do for a cheap replacement of character controller in unity.

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:

  1. 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).
  2. Kinetic body don't collide with scenery (don't listen collision).
  3. Character controller don't rotate.
  4. 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)

Currently my code is this one, with sweeptest(): http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.SweepTest.html


private void UpdateSurfacePosition()
Ray//origine, direction
ground_check_ray = new Ray( gameObject.transform.position, -gameObject.transform.up);// * (Momentum.magnitude + 1));
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;
raycast_result.normal = raycast_result.normal.normalized;
onGround = false;

debug1 = "Normal > " + raycast_result.normal.ToString()
+ " Position > "+ raycast_result.point.ToString()
//+" transform > "+ raycast_result.transform.name.ToString()
+ " Contact > " + contacts.Length

if ( onGround )

//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;
//if forward close to dot.Y = abs(1) choose -up if 1 and up if -1
UpdateMoveOrientation( gameObject.transform.forward, raycast_result.normal );


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement