Different enemy weapons/ animations

curious if anyone hs figured out how to give enemies different attacks like a boss for example like if player is close enough then they do a certain attack or use a certain weapon but at distance they do something else or use a different weapon?

You should calculate distance between enemy and player. Then just call right function by using distance and simple if else statement.

For the animation you can use boolean to call the another one, for example if enemy is closer than 5 meters set this boolean true and if not set is false.

I just wanted to give you an idea of course I did not explain the details but if you do it like this, it works

Have a nice day!

You should calculate distance between enemy and player. Then just call right function by using that distance and simple if else statement.

For the animation you can use boolean to call the another one, for example if enemy is closer than 5 meters set this boolean true and if not set it false.

I just wanted to give you an idea of course I did not explain the details but if you do it like this, it works

Have a nice day!

This is on the right track…

I think what I would do is add fields to WeaponConfig that specified an alternate weapon to load… Something like this:

[SerializeField] bool isRanged=false;
[SerializeField] WeaponConfig altWeapon;
[SerializeField] float switchWeaponThreshhold = 6.0f;

public WeaponConfig GetAltWeaponIfNeeded(float currentRange)
{
    if(altWeapon==null) return null;
    if(isRanged && (currentRange < switchWeaponThreshhold)) return altWeapon;
    if(!isRanged && (currentRange>switchWeaponThreshhold)) return altWeapon;
    return null;
}

Then in Fighter, in Update()

Vector3 distanceToTarget = Vector3.Length(transform.position, target.transform.position);
WeaponConfig altWeapon = currentWeapon.GetAltWeaponIfNeeded(distanceToTarget);
if(altWeapon) EquipWeapon(altWeapon);

seems like it should work but Vector3.Length dosnt exist and i had to make the distance to target a float then use Vector3.Distance and compare the 2 and filling the alt weapon slots didnt work either,
strange

giving me a null reference on the line i declare distance to target

maybe i could set alt weapon to be in fighter instead of on config

so after setting everything in fighter ignoring the weapon config script it works kind of still getting a null reference with distance to target

so after looking at it more i was declaring the distance too early in update

Sorry, the script I wrote was off the cuff in this Editor, so I accidentally put in the wrong method… I also messe up and used Vector3 distanceToTarget when it should have been float. Gotta love writing scripts off the cuff.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms