nickmattinson / ZXYZ

Top-Down 2D Dungeon Crawler
1 stars 0 forks source link

Enemy Spinning #57

Closed MikeMMattinson closed 2 months ago

MikeMMattinson commented 2 months ago

Player pushes into enemy and enemy spins around.

MikeMMattinson commented 2 months ago

From ChatGPT3.5: Here are a few steps you can take to address the spinning issue:

Check Collision Handling: Make sure that your player and enemy game objects have appropriate colliders and rigidbodies attached to them. Ensure that the collision detection settings are suitable for your game's requirements. For instance, you might want to use triggers for detection without physical interaction or handle collisions using physics.

Collision Detection Method: If you are using collision detection methods such as OnCollisionEnter2D or OnTriggerEnter2D in your scripts, review the code inside these methods. Ensure that you handle the collision behavior correctly without causing unwanted rotations or movements.

Adjust Physics Properties: Depending on your game's physics settings, you may need to adjust properties such as friction, mass, or constraints to prevent spinning when collisions occur.

Debugging Collision Issues: Use Unity's debugging tools to visualize collisions and rigidbody interactions. You can enable gizmos, debug logs, or breakpoints in your scripts to understand when and why the spinning occurs.

nickmattinson commented 2 months ago
using UnityEngine;

public class EnemyController : MonoBehaviour
{
    private bool rotating = true; // Flag to control enemy rotation

    private void Update()
    {
        if (rotating)
        {
            // Rotate the enemy as needed
            // Example: transform.Rotate(Vector3.up * Time.deltaTime * rotationSpeed);
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            // If collided with the player, stop rotating
            rotating = false;
        }
    }
}