How do I spawn different 3D enemies with independent animations?

0 favourites
  • 5 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Objective:

    The objective is to have enemy spawners scattered around the map to spawn new enemies every X seconds (a feature already implemented). These enemies are 3D objects with a sprite containing animations being projected onto the 3D object's bottom face. The objective is to have every new enemy spawned have the correct animations based on their angle. Example:

    If the enemy's angle is 45 degrees, the animation for that instance will be "Southwest_Idle", whereas if its angle is 0 degrees, the animation will be "East_Idle".

    The angle is determined by the Enemy's position in relation to the player.

    Current approach:

    For every tick, I set an instance variable called "selfAngle" in the enemy 3D object to angle(Self.X , Self.Y, Player.X, Player.Y). Then, I compare the value in that instance variable to check if the number stored in there is greater or equal to an angle and less than another (e.g. >= 0 and < 30). If that is true, the program set the correct animation accordingly.

    In terms of having the correct animation according to the angles, this is working.

    Problem:

    Since all the 3D objects being spawned reference the same single instance of the animation sprite, all the enemy instances face the same direction.

    A possible solution that I thought of was to spawn a new instance of the sprite containing the animations and project that specific instance onto the new corresponding 3D object that was also generated. However, I have no idea how to do that and need help.

    What could I do to solve this problem?

    Link for the C3 Project:

  • It might be the issue where the 3D object you want to use multiple times needs to be made a container with the sprite inside. In the properties for the 3D object click "create" under container and add the sprite to it. Then every new spawned 3D object of that type has a separate copy of the sprite that will be addressed individually when that object is being manipulated. Then it just works.

    If you've already done that, then I don't know.

  • No, I haven't done that yet. I will give it a shot and I'll come back to say if it worked or not.

    Cheers!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I have just tried the container approach and it worked like a charm. Thank you bigcatrik!

    I just created a container in the 3D object and included the sprite with the animation in it. Now, every time when the enemy spawn, the animation works.

    Screenshot of the game working:

    Screenshot of the container:

  • Hippity-hoppity your code is now my property.

    (THANK YOU!!)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)