RayCast vehicle to wall collision

Software: Away3D 4.x

ron~, Newbie
Posted: 16 February 2013 04:01 PM   Total Posts: 15

Hi Guys,

I am using RaycastVehicle for a vehicle simulation and have collision with walls. How can I customize the collision with the walls so my vehicle won’t top over when colliding at high speeds? Anybody have any clue?

Thanks in advance

   

Avatar
Luca, Sr. Member
Posted: 16 February 2013 08:45 PM   Total Posts: 230   [ # 1 ]

If the wall are a rigid body “AWPRigidBody”
have you tryed to change the “restitution” factor value ?

   

ron~, Newbie
Posted: 17 February 2013 06:31 AM   Total Posts: 15   [ # 2 ]

Yes I am using AWPRigidBody. I tried using restitution (0.4) but car doesn’t slides through walls when it hit them.When the car’s edges(box shaped) hitting on wall, the car just sticking on the wall or giving bouncy results.

   

Daniel88, Newbie
Posted: 21 February 2013 03:27 AM   Total Posts: 6   [ # 3 ]

To make things look smoother you might want to change the collider or manually change the center of mass to the back of the chassis, or move it around dynamically, or apply some force or angular velocity proportional to the angle (linearly, squared or cubed or w/e) between up axis of the vehicle and the world up axis, that will counter-act the rotation.

   

Avatar
Luca, Sr. Member
Posted: 21 February 2013 07:04 AM   Total Posts: 230   [ # 4 ]

Sry, but i have little time. I agree with what he says Daniel88
Anyway, I do not have a precise idea of the problem… Can you publish your demo for exampe by using this free host provider: http://www.altervista.org
or your http server ?

I have make some test, and i have a little demo here:
http://www.estiva2.altervista.org/SiteGames/Kart/Kart.php

I don’t have problem when the kart collide whit walls, so do you need to get something like this ?

Or publish the code you use for example i use this:

  //———————————————————————————————————————————————————————-
  // Create chassis shape
  //———————————————————————————————————————————————————————-
  private function createCarShape():AWPCompoundShape
  {
 
  //
  var boxShape1:AWPConvexHullShape = new AWPConvexHullShape( CarBoundMesh.geometry );
 
  //
  var BBS:Vector3D = new Vector3D(
  CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).maxX - CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).minX,
  CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).maxY - CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).minY,
  CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).maxZ - CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).minZ );

 
  //
  // bbc[0].x, bbc[0].y, bbc[0].z
  //
  var carShape:AWPCompoundShape = new AWPCompoundShape();
 

 
  // Shifting the center of mass
  // If you want to shift the center of mass of a PhysicsNode or PhysicsVehicleNode, you will have
  // to create a CompoundCollisionShape and attach the real CollisionShape for the PhysicsNode to it with an offset.
  // CompoundCollisionShape compoundCollisionShape=new CompoundCollisionShape();
  // BoxCollisionShape boxCollisionShape=new BoxCollisionShape(new Vector3f(0.5f,0.5f,0.5f));
  // compound.addChildShape(boxCollisionShape, new Vector3f(0,1,0));

  // effectively shifts the center of mass with respect to the chassis
  carShape.addChildShape( boxShape1, new Vector3D( 0, 0, 0 ), new Vector3D( 0, 0, 0 ) );

  // 
  CarContainer.getChildAt( GetChildByName( CarContainer, “CollisionBB1” ) ).visible = false;

 
  //
  return carShape;
  }

the get the right position for the shape, ( which is a mesh created around the model in 3ds max ) i use this code

  else if( ( FilterMeshName( mesh.name ) == “CollisionBB1” ) )
  {
    //
    bbc.push( mesh.bounds.boundingRenderable.position );
    //
    CarBoundMesh = mesh;
  }

Unfortunately the Away implenteation of Bullet are not complete and has some differences from the original… time to time i suppose…

   

ron~, Newbie
Posted: 21 February 2013 09:05 AM   Total Posts: 15   [ # 5 ]

Thanks a lot for sharing your knowledge,

As per Daniel’s suggestion, I have moved the center of mass to back of the chassis. Now its showing better results. I think by applying a central impulse ,fine tuning the values of restitution and friction between the car and wall can be smooth the results as well.

Thanks Luca for your extreme help for resolving this issue. Since its a client game, I’m restricted to upload a playable demo. But I’ve uploaded a video of that issue: http://www.youtube.com/watch?v=TmX7-vb_w-4&feature=youtu.be

Thank You

   

Avatar
Luca, Sr. Member
Posted: 21 February 2013 09:25 AM   Total Posts: 230   [ # 6 ]

With pleasure, but I want to challenge you in your game ( like neeeeeeed foooooor speeeeeeeeeeed or Gran Turismo ) ha smile

so do you know this:

http://www.smartfoxserver.com/
or:
http://www.electrotank.com/

and for the AI try look this:
http://supertuxkart.sourceforge.net/


good job Ron….

   

ron~, Newbie
Posted: 21 February 2013 09:45 AM   Total Posts: 15   [ # 7 ]

haha thats a good idea. Supertuxkart is always a good reference, its an amazing team work too.

Also you can support supertuxkart here: http://twtpoll.com/ragr0e

   

Avatar
Luca, Sr. Member
Posted: 21 February 2013 10:55 AM   Total Posts: 230   [ # 8 ]

wink but you can also use:

  //——————————————————————————————————————————————————————-
  //
  //——————————————————————————————————————————————————————-
  private function NavigateTowardsWaypoint()
  {

  // Now we just find the relative position of the waypoint from the car transform,
  // that way we can determine how far to the left and right the waypoint is.
  // Calculate the target position relative to the this transforms coordinate system.
  // eg. a positive x value means the target is to the right of the car,
  // a positive z means the target is in front of the car
  relativeTarget = car.getRigidBody().skin.inverseSceneTransform.transformVector( waypoints[currentWaypoint] );
  relativeTarget1 = car.getRigidBody().skin.inverseSceneTransform.transformVector( waypoints[currentWaypoint+1] );
  // Above solution only works if the item/ball is directly on the stage. If it isnt, you should use ball.scenePosition!
  //item.position = targetContainer.inverseSceneTransform.transformVector(item.scenePosition);
 
 
  // By dividing the horizontal position by the magnitude, we get a decimal percentage of
  // the turn angle that we can use to drive the wheels
  // Calculate the target angle for the wheels, so they point towards the target
  // targetAngle = Math.atan2( relativeTarget.x, relativeTarget.z );
  // targetAngle1 = Math.atan2( relativeTarget1.x, relativeTarget1.z );
 
  // The wheels have a maximum rotation angle
  targetAngle = Clamp( Math.atan2( relativeTarget.x, relativeTarget.z ), -MaxSteeringAngle, MaxSteeringAngle );
  // The wheels have a maximum rotation angle
  targetAngle1 = Clamp( Math.atan2( relativeTarget1.x, relativeTarget1.z ), -MaxSteeringAngle, MaxSteeringAngle );

 
  //
  if( DebugAI )
  {
  //
  Gizmos.position = waypoints[currentWaypoint];
 
  ConnectionLine.start = car.getRigidBody().skin.position;
  ConnectionLine.end = waypoints[currentWaypoint];
  // trace( waypoints[currentWaypoint] + ” - ” + car.getRigidBody().transform.position );
 
  ConnectionLine.startColor = ConnectionLine.endColor = 0xFFFFFF;
  ConnectionLine.thickness = 2;
 
  // trace( waypoints[currentWaypoint] + ” ” + car.getRigidBody().position );
  // trace( Dx + ” ” + Dz );

  // GVector2.start = new Vector3D();
  // GVector2.end = DTV; 
  // GVector1.startColor = GVector1.endColor = 0x0000FF;
  // GVector2.startColor = GVector2.endColor = 0xFFFFFF;
  // GVector1.thickness = GVector2.thickness = 2;
  //
  //trace( targetAngle );
  //
  GVector1.start = car.getRigidBody().skin.sceneTransform.position;
  //
  var Pe:Vector3D = new Vector3D(
    car.getRigidBody().skin.sceneTransform.position.x + 300 * ( Math.sin( targetAngle ) ),
    car.getRigidBody().skin.sceneTransform.position.y,
    car.getRigidBody().skin.sceneTransform.position.z + 300 * ( Math.cos( targetAngle ) ) );
  GVector1.end = Pe;
 
  }

  // This just checks if the car’s position is near enough to a waypoint to count as passing it,
  // if it is, then change the target waypoint to the next in the list.
  if ( relativeTarget.length < 700 )
  {
  //
  currentWaypoint++;
  //
  if( currentWaypoint >= waypoints.length )
  {
    currentWaypoint = 0;
  }
  }

  }

challenge, challenge, challenge….. smile

   

ron~, Newbie
Posted: 21 February 2013 11:31 AM   Total Posts: 15   [ # 9 ]

a helpful logic! I’ll surely refer your code once I started working on it, at the moment I’m doing a skill based driving game, no opponents.

Cheers!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X