[Closed] Find the velocity of the Character Controller

I have an gameObject instantiating at the position of the character controller’s camera along its z-axis at speed.
Problem is that when I move the character, the gameObject instantiates off its mark.
I think I know how to fix it by just adding the gameObject velocity and the character controller velocity together.

Only problem with that is that I can not figure out the character controllers’s velocity variable e.g. I have:

gameObject.velocity.x+= ???.velocity.x 

Note: gameObject is placeholder for variable name.

Edit: I’m sorry if my question is unclear, I already have a object (Lets call this projectile) instantiating from the z-axis of character’s camera.

That fires fine, but what I am unsure about is how to make it so the projectile doesn’t stop going directly down z-axis when the character is moving.(momentum changing where projectile is aimed)

I am/was trying to find the character controller’s(component) velocity to stop the projectile being moved off course.

Edit 2:

Screenshot to try to help clear things up. [2604-problem+screenshot.png|2604]

Is this what you wanted?

The property CharacterController.velocity returns the character velocity, but it’s based in the actual distance the character moved from last Move or SimpleMove - which may return some unexpected values. A more reliable alternative is to measure the character speed at Update:

var player: Transform; // drag the character here
var playerVel: Vector3;
private var lastPos: Vector3;

function Start(){
  lastPos = player.position; // initialize lastPos
}

function Update(){
  // calculate displacement since last Update:
  var moved = player.position - lastPos;
  // update lastPos:
  lastPos = player.position;
  // calculate the velocity:
  playerVel = moved / Time.deltaTime;
}

Notice that playerVel is a Vector3, thus it holds the speeds along the axes X, Y and Z in its x, y and z components. Usually you should add playerVel to the object’s velocity in order to keep it constant relative to the player, but you can add only the X component, if this makes more sense in your case.