List of usage examples for com.badlogic.gdx.ai.steer Steerable getLinearVelocity
public T getLinearVelocity();
From source file:com.mygdx.game.CustomCollisionAvoidance.java
License:Apache License
@Override public boolean reportNeighbor(Steerable<T> neighbor) { // Calculate the time to collision relativePosition.set(neighbor.getPosition()).sub(owner.getPosition()); relativeVelocity.set(neighbor.getLinearVelocity()).sub(owner.getLinearVelocity()); float relativeSpeed2 = relativeVelocity.len2(); float timeToCollision = -relativePosition.dot(relativeVelocity) / relativeSpeed2; if (Float.isNaN(timeToCollision)) { timeToCollision = 0.0f;//from w w w . jav a 2 s.co m } // If timeToCollision is negative, i.e. the owner is already moving away from the the neighbor, // or it's not the most imminent collision then no action needs to be taken. if (timeToCollision <= 0 || timeToCollision >= shortestTime) return false; // Check if it is going to be a collision at all float distance = relativePosition.len(); float minSeparation = distance - (float) Math.sqrt(relativeSpeed2) * timeToCollision /* shortestTime */; if (minSeparation > owner.getBoundingRadius() + neighbor.getBoundingRadius()) return false; // Store most imminent collision data shortestTime = timeToCollision; firstNeighbor = neighbor; firstMinSeparation = minSeparation; firstDistance = distance; firstRelativePosition.set(relativePosition); firstRelativeVelocity.set(relativeVelocity); return true; }