0

I am having a problem that when using a Character Controller with Playmaker my player is falling below the ground. When using a capsule collider and rigid body my player is moving good but I don’t having any collision with the walls when its position and rotation are frozen. When I untick x and z freeze position my player is sliding towards its z direction (means space set to self) but having collision to walls.

In Playmaker I am using translate for movement and using my own Vector3 variable named forward and backward with x and y as zero and z as 10 and -10.

Bart
  • 19,692
  • 7
  • 68
  • 77
Tech247
  • 11
  • 1
  • 2

1 Answers1

0

Translating is like "teleporting".

You need to use set velocity or add force.

And of course a collider to you walls.

If you really want to use "translate", you can use this script :

 #pragma strict

var layerMask : LayerMask; //make sure we aren't in this layer
var skinWidth : float = 0.1; //probably doesn't need to be changed
private var minimumExtent : float;
private var partialExtent : float;
private var sqrMinimumExtent : float;
private var previousPosition : Vector3;
private var myRigidbody : Rigidbody;
//initialize values
function Awake() {
   myRigidbody = rigidbody;
   previousPosition = myRigidbody.position;
   minimumExtent = Mathf.Min(Mathf.Min(collider.bounds.extents.x, collider.bounds.extents.y), collider.bounds.extents.z);
   partialExtent = minimumExtent*(1.0 - skinWidth);
   sqrMinimumExtent = minimumExtent*minimumExtent;
}

function FixedUpdate() {
   //have we moved more than our minimum extent?
   var movementThisStep : Vector3 = myRigidbody.position - previousPosition;
   var movementSqrMagnitude : float = movementThisStep.sqrMagnitude;
   if (movementSqrMagnitude > sqrMinimumExtent) {
      var movementMagnitude : float = Mathf.Sqrt(movementSqrMagnitude);
      var hitInfo : RaycastHit;
      //check for obstructions we might have missed
      if (Physics.Raycast(previousPosition, movementThisStep, hitInfo, movementMagnitude, layerMask.value))
         myRigidbody.position = hitInfo.point - (movementThisStep/movementMagnitude)*partialExtent;
   }
   previousPosition = myRigidbody.position;
}
ababab5
  • 284
  • 4
  • 14