Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Compensación no deseada de rotación de bala Unidad

Estoy tratando de que un enemigo rodee al jugador y le dispare balas. Sin embargo, cada vez que el enemigo dispara, la bala está ligeramente alejada del jugador y continúa disparando más lejos de la posición de los jugadores.

este es el comportamiento de los enemigos

 using System.Collections; using System.Collections.Generic; using UnityEngine; public class CirclingScript : MonoBehaviour, IPooledObject { public Transform tf; public Transform Target; public GameObject Ship; public GameObject WaveMaker; public EnemyScript enemyscript; public string BulletName; ObjectPools objectPooler; private int I; // Wave number public int BulletAmount; public float angle; public float Radius; public float RotateSpeed; private float Timer; public float Health; private Quaternion BulletRot; public void OnObjectSpawn() { WaveMaker = GameObject.Find("EnemyWaveMaker");//gets the game object enemyscript = WaveMaker.GetComponent<EnemyScript>();// gets the scripts for the wave makers I = enemyscript.i; Ship = GameObject.Find("Ship");//gets the game object Target = Ship.GetComponent<Transform>();// gets the Transform //https://answers.unity.com/questions/1068513/place-8-objects-around-a-target-gameobject.html thank you ^-^ angle = enemyscript.RotSpace * Mathf.PI * 2f / enemyscript.Waves[I].Amount; RotateSpeed = enemyscript.Waves[I].RotateSpeed; Radius = enemyscript.Waves[I].Radius; } void Start() { objectPooler = ObjectPools.Instance; } void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.CompareTag("Bullet")) { Health -= coll.GetComponent<DamageScript>().Damage; } if (Health <= 0) { objectPooler.SpawnFromPool("Boom", tf.position, Quaternion.identity); gameObject.SetActive(false); } } // Update is called once per frame void Update() { angle += RotateSpeed * Time.deltaTime; Timer += Time.deltaTime; Vector2 offset = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)) * Radius; tf.position = (Vector2)Target.position + offset; if (Timer >= 2f) { Vector3 difference = Target.position - tf.position; float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; BulletPatternsModule.ShootArc(angle, BulletAmount, BulletName, tf, rotationZ); Timer = 0f; } } }

y el código para disparar las balas

 public static void ShootArc(float ArcSize, int BulletAmount, string BulletName, Transform tf, float Offset)//All arcs are in angles, not radians { float angle = 0; angle = Offset;//Offset is to the left for (int i = 0; i < BulletAmount; i++) { float AngleStep = ArcSize / BulletAmount;//Gets the step size for arc angle += AngleStep; objectPooler.SpawnFromPool(BulletName, tf.position, Quaternion.Euler(0, 0, angle));//Shoots the bullet } }

El desplazamiento hace que los enemigos sean casi inútiles.

Cualquier ayuda sería apreciada :) (más texto para poder publicar la pregunta. ¿No es divertido?)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Será más fácil hacer que el enemigo mire al jugador usando esta función

 transform.LookAt(target.position);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!