Decomposition of speed vector

hi all,

i have some trouble with decomposition of vectors for steering behaviour seek which im trying to implement.

i have space ship which have position and linear velocity, heading in somewhere
i also have random destination point anywhere, not necessarily in the direction of ship

how can i decomposite the linear velocity, to get vector that represents the length of the velocity facing in the target direction?

pseudo code:
// Get the direction to target
Vector3f approachingDirection = targetPosition.subtract(myPosition).normalize();
// Get the approaching speed length
float approachingSpeed = myLinearVelocity.extractApproachingSpeed(approachingDirection).length();

im thinking about experimenting with dot product, but i dont know :frowning:

thanks ascaria

What you ask for would be simply vector.length()?

@normen no, no, sorry for confusion

i want to know approaching speed to the target if linear velocity does not aiming directly to the target

i know myPosition “A”, targetPosition “B”, myLinearVelocity “V”, and i want to solve for “X”, how big speed component is in that direction

I think the vector dot product is what you are looking for.

yea im thinking about that. it seems to be linear if we going from angle 0° to 90°
at angle 0° i want full speed and angle 90° have zero speed…
angle 180° i need zero speed or full backward speed i dont know, negative length should be okay
but i dont know if i want half of the speed if we are going at 45° angle, but for simplicity it could be enough precision… at the end, it is only a central linear force applied to rigidbody

edit: erm it might be harder than it seems, i have now:
* Do state things.
public void update(float tpf) {
// Set linear velocity and physics location of the entity
mass = rigidBody.getMass();

    // Determine distance from target
    actualDistance = physicsLocation.distance(loc);

    // Look at target only if we are far away
    if(actualDistance >= criticalApproachingDistance) {
        Quaternion targetRotation = new Quaternion();
        Vector3f dir = loc.subtract(physicsLocation).normalizeLocal();
        Vector3f up = rigidBody.getPhysicsRotation().getRotationColumn(1);
        targetRotation.lookAt(dir, up);

    // Calculate steering force
        .multLocal(/*TODO: implement engine movementPower*/ movementPower * mass * tpf);

    // Calculate braking distance
    Vector3f speedSquared = Vector3fHelper.square(linearVelocity);
    Vector3f acceleration = steering.divide(mass);
    float brakingDistance = 0.5f * speedSquared.divide(acceleration).length();

    // Determine if we are approaching to (dot > 0), or distancing from (dot < 0) the target
    Vector3f targetDir = loc.subtract(physicsLocation).normalize();
    float dot = linearVelocity.normalize().dot(targetDir); // 1 moving towards target, -1 moving away from target

    // If we are too near and too slow, stop and pop state
    Vector3f hybnost = linearVelocity.mult(mass).mult(1 / tpf);
    if(hybnost.length() < (mass / tpf) && actualDistance < criticalApproachingDistance) {
        ai.server.broadcast(new ChatMessage( + ": destination reached: " + Vector3fHelper.round(physicsLocation, 2)));
    } else {
        // Determine if we are in slowing area
        if(dot < 0 || actualDistance >= brakingDistance) {
            // We can accelerate
        } else {
            // We are in braking distance


and i should add some dot product to this mess :slight_smile: