hey everyone!
how do i pick up an object so that the gameobject is attached to my FPS arms?
untill now i managed to get a UI appear within a trigger zone saying “pick up object on F”.
however i only actiave the pickup animation on F and no object is in my arms.
do i need to set the gameobject as disabled in the scene and enable it on pickup F or how ?
all the bests
@linelade This would be a good example, you might have to modify it to fit your needs.
private bool HoldingWeapon;
private LayerMask Weapon;
Vector3 hold;
Vector3 point;
public Transform HeldWeapon;
public Transform self;
Collider collider;
public float range = 2;
public GameObject Gun;
and this would be what you would put in an if statement checking if the F button is pressed.
RaycastHit hit;
Vector3 forward = transform.TransformDirection(Vector3.forward) * 3f;
if (Physics.Raycast(transform.position, (forward), out hit, range, Weapon))
{
hold = transform.TransformVector(0, 0, 0);
Gun = hit.collider.gameObject;
collider = Gun.GetComponent<Collider>();
collider.enabled = false;
Gun.transform.parent = HeldWeapon;
Gun.transform.localRotation = Quaternion.Euler(0, 0, 0);
Gun.transform.localPosition = Vector3.zero;
HoldingWeapon = true;
Gun.GetComponent<Rigidbody>().isKinematic = true;
Hope this helped, have a nice day.