My enemy jump towards to the player is way too fast… How do i slow it down?
void Jump ()
{
RaycastHit hit;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, fwd * 100,Color.cyan);
if(Physics.Raycast(transform.position,fwd, out hit, 100) && !isDetected && !isjump)
{
Debug.Log (hit.transform.name);
if (hit.collider.gameObject.tag == "Player")
{
//isDetected = true;
//target = hit.collider.gameObject;
target = hit.transform.gameObject;
float gravity = Physics.gravity.magnitude;
// Selected angle in radians
float angle = initialAngle * Mathf.Deg2Rad;
// Positions of this object and the target on the same plane
Vector3 targetPosition = new Vector3(target.transform.position.x, 0,target.transform.position.z);
Vector3 currentPosition = new Vector3(transform.position.x, 0, transform.position.z);
// Planar distance between objects
float distance = Vector3.Distance(targetPosition, currentPosition);
// Distance along the y axis between objects
float yOffset = transform.position.y -target.transform.position.y;
float initialVelocity = (1 / Mathf.Cos(angle)) * Mathf.Sqrt((0.5f * gravity * Mathf.Pow(distance, 2)) / (distance * Mathf.Tan(angle) + yOffset));
Vector3 velocity = new Vector3(0, initialVelocity * Mathf.Sin(angle), initialVelocity * Mathf.Cos(angle ));
// Rotate our velocity to match the direction between the two objects
float angleBetweenObjects = Vector3.Angle(Vector3.forward, target.transform.position - currentPosition)* (target.transform.position.x > transform.position.x ? 1 : -1);;
Vector3 finalVelocity = Quaternion.AngleAxis(angleBetweenObjects, Vector3.up) * velocity;
//Debug.Log ("Distance : " + distance);
// Fire!
rb.velocity = finalVelocity ;
//Debug.Log ("Final Velocity : " + finalVelocity);
isjump = true;
isDetected = true;
}
}
}