Search Unity

C# Problem - 2D Game, Need to Trigger Animation and Projectile Fire

Discussion in 'Scripting' started by DarthModulus, Sep 4, 2014.

  1. DarthModulus

    DarthModulus

    Joined:
    Sep 3, 2014
    Posts:
    2
    Hello everyone.

    I'm not new to programming in C#/C++, but I'm a blasted noob at Unity3D (sorry. lol). In any case...

    Here is my problem. I am making a 2D game that is an infinite runner. The infinite runner runs vertically. Objects spawn on the screen in certain preset positions based on spawn points I set. That's all gravy. The part I'm working on now is one of the spawned enemies. Basically, the player makes contact with the enemy via a collider (side note: up until this point I'd been using a sphere collider, should I do this or use 2D Circle Collider? the models for the player and enemies are 3D but the game plays in 2D). This collider is supposed to be a trigger of some sort, and will make the enemy play an animation of him firing his weapon. (The collider is not meant to harm the player but solely to trigger this action.)

    Where I'm having trouble is, I can't seem to get these things to happen:

    1) Upon detection of collision (which DOES happen, I've put in debugging code to log the event's success), the enemy plays the firing animation (in this case, a 3D metarig/armature that is attached to the model).

    2) The projectile is instantiated at the point of release, and then travels in the direction of the player.

    3) The projectile either collides with player or doesn't - this much is irrelevant because I've gotten the colliders to play nice enough.

    So the problem is mostly getting the event of player entering the field for the enemy's detection radius to cause the enemy to fire the projectile (i.e., animation plays as object is instantiated and flies along a vector determined upon detection). As a side note, my vector math was a little rusty... I looked at the vector maths tutorial from YouTube, and it's not helping me determine the path along which the projectile should be shot.

    Any and all help is appreciated. I have a lot of code involved in this right now among a few different scripts... if anyone needs to see what I have , let me know. But something tells me this is something stupid I'm overlooking, and why bother you nice folks with scads of code if it's not necessary? :)

    Thanks to any and all in advance, for even reading all this and giving any thought to helping. God bless.