private void JumpAtPlayer(CChicken chicken, CCSPlayerController player) { var direction…
- User
private void JumpAtPlayer(CChicken chicken, CCSPlayerController player) { var direction = Vector3.Normalize(player.PlayerPawn.Value!.AbsOrigin!.ToVector3() - chicken.AbsOrigin!.ToVector3()); var jumpVelocity = new Vector(direction.X, direction.Y, 300.0f);
chicken.Teleport(new Vector(chicken.AbsOrigin.X, chicken.AbsOrigin.Y, chicken.AbsOrigin.Z + 20), velocity: jumpVelocity); }у меня есть позиция игрока, позиция курицы, телепортируй курицу немного в мою сторону
- Assistant
If you want to teleport the chicken slightly towards the player's current position, you need to modify the chicken's position to be closer to the player before setting the new velocity. Here's a subtle way to make the chicken jump towards the player:
private void JumpTowardsPlayer(CChicken chicken, CCSPlayerController player) { // Calculate the direction from the chicken to the player var direction = Vector3.Normalize(player.PlayerPawn.Value!.AbsOrigin!.ToVector3() - chicken.AbsOrigin!.ToVector3()); // Determine the step size towards the player, adjust this value based on how close you want the chicken to be float stepSize = 10.0f; // This can be adjusted as needed // Calculate a new position slightly closer to the player var newPosition = new Vector( chicken.AbsOrigin.X + direction.X * stepSize, chicken.AbsOrigin.Y + direction.Y * stepSize, chicken.AbsOrigin.Z + direction.Z * stepSize ); // Define jump velocity towards the player var jumpVelocity = new Vector(direction.X, direction.Y, 300.0f); // Teleport the chicken to the new position with the calculated velocity chicken.Teleport(newPosition, velocity: jumpVelocity); }Explanation:
-
Direction Calculation: Calculate the normalized direction vector from the chicken to the player. This gives the direction in which the chicken needs to move.
-
Step Towards Player: We calculate a new position for the chicken by moving it a small step towards the player's direction. The
stepSizedetermines how large the step should be. -
New Position: This position brings the chicken slightly closer to the player.
-
Teleport with Velocity: Finally, you teleport the chicken to this new position with a jump velocity defined to give an arc effect.
Adjust the
stepSizeto control how far the chicken should move towards the player. -