|
Post by quickdraw on Oct 24, 2018 0:51:02 GMT
Hi, I need some help working out how to create multiple LeftHandIK transforms for the same weapons as I have various characters that use the same weapon but have different leftHandIK transform positions. I'm not sure on how the best way to go about it. I could create a child game object on the parent of the player and reference the vShooterWeapon leftHandIK to this. Unless there is a better way?
|
|
|
Post by shadex on Oct 25, 2018 18:51:58 GMT
Hi, I need some help working out how to create multiple LeftHandIK transforms for the same weapons as I have various characters that use the same weapon but have different leftHandIK transform positions. I'm not sure on how the best way to go about it. I could create a child game object on the parent of the player and reference the vShooterWeapon leftHandIK to this. Unless there is a better way? If all your characters have the same grip, and it's just the model needing to be adjusted, check the import settings and reconfig the avatar. I know SFBay has a huge problem with this, and it will also hurt other animations down the line (both feet and hands).
Really hard to give advice, because i don't know how many characters, and how many LeftHandIK positions you might need. If they are enemy's vs players, make 2 sets of weapons and make the enemy drop the players bow.
Now if you need it for every character and every gun, then your going to have to make a script that updates the transform on equip. Easiest way would be to make some empty gameobjects on the character that store the correct leftHandIK transform. Call it ShotgunIKPosition. Then put a script on the weapon that onStart() searches for ShotgunIKPosition and sets the Shotgun's LeftHandIK to ShotgunIKPosition. I would think the easiest way would be to search for it's own name in the empty gameobjects that are storing the transform.
So find a gameobject with the weapons gameobject.name to the weapons gameobject.name + "IKPosition" string. Not the best coder, but i think this should work "gameObject.name.Equals(gameObject.name + "IKTarget");" That way you don't have to code each weapon, and just create empty gameobjects that follow the same naming convention (namehereIKPosition) on any new character you create.
If you want more then just the weapon transform, make a script for each weaponIKPosition that has any values you want to change on the gun (fire rate, damage, etc), and have the update script on the weapon set those variables as well.
|
|
|
Post by quickdraw on Oct 26, 2018 3:19:40 GMT
shadex - thanks for this. Before I saw your post I managed to come up with a solution - I'll share here in case anyone could find it useful - it's not perfect, but it will do for now. It basically creates a list (that you can add each of the characters names and transform/rotations for the LeftHandIK), it finds the player by name, strips out the instance name if you have player instance enabled) and adjusts the position of the leftHandIK transform. This script should be added to the weapon. Where ShooterWeapon is. using UnityEngine;
using System;
using System.Collections.Generic; // Import the System.Collections.Generic class to give us access to List<>
public class wepTransformList : MonoBehaviour {
//This is our custom class with our variables
[System.Serializable]
public class WeaponTransformList{
public string SkinName;
public Vector3 WeaponLeftIK;
public Vector3 WeaponIKRotation;
}
//This is our list we want to use to represent our class as an array.
public List<WeaponTransformList> WeaponIKList = new List<WeaponTransformList>(1);
private GameObject player;
private GameObject mGameObject;
void AddNew(){
//Add a new index position to the end of our list
WeaponIKList.Add(new WeaponTransformList());
}
void Remove(int index){
//Remove an index position from our list at a point in our list array
WeaponIKList.RemoveAt(index);
}
void Start ()
{
player = GameObject.FindWithTag("Player");
var playername = player.gameObject.name;
var newPlayerName = playername.Replace("Instance", "");
newPlayerName.Substring(0, newPlayerName.Length - 1);
var newPlayerName2 = newPlayerName.Trim ();
Debug.Log ("New PN: (" + newPlayerName2 + ")");
foreach(WeaponTransformList wtl in WeaponIKList)
{
var skinname = wtl.SkinName;
if (skinname == newPlayerName2) {
Debug.Log ("Found player name that is using this weapon");
Debug.Log ("Transform Position: " + wtl.WeaponLeftIK);
var xpos = wtl.WeaponLeftIK.x;
var ypos = wtl.WeaponLeftIK.y;
var zpos = wtl.WeaponLeftIK.z;
var xrot = wtl.WeaponIKRotation.x;
var yrot = wtl.WeaponIKRotation.y;
var zrot = wtl.WeaponIKRotation.z;
Transform lefthandtransform;
lefthandtransform = gameObject.transform.Find ("renderer/leftHandIK");
lefthandtransform.localPosition = new Vector3(xpos, ypos, zpos);
lefthandtransform.localRotation = Quaternion.Euler(xrot, yrot, zrot);
return;
}
else
Debug.Log ("Could not find skin name leftIK defined for this weapon");
}
}
}
|
|
|
Post by quickdraw on Oct 26, 2018 22:11:08 GMT
updated the code in the post above. Works better and searched for the child gameObjects that the script is attached to.
|
|