hey there, i have searched alot and no one seems to have my problem
so basically im making a fps game and i have pickup/drop weapon system , so i would like to smooth the rotation of the weapon when getting picked up like i smoothed its position but not rotation also how pickup works is when u press e the weapon becomes a child of the player and gets a new vector3
i’ll leave my code for the pickup/drop system here, thanks for reading and have a nice day.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUpController : MonoBehaviour
{
public GunScript gun_Script;
public Rigidbody rb;
public BoxCollider coll;
public Transform player, gunPosition, fpsCam;
public float pickUpRange;
public float dropForwardForce, dropUpwardForce;
private Vector3 Velocity = Vector3.zero;
public float SmoothTime = 0.3f;
public bool equipped;
public static bool slotFull;
void Start() {
Debug.Log("The Script is working");
if(!equipped) {
gun_Script.enabled = false;
rb.isKinematic = false;
coll.isTrigger = false;
}
if(equipped) {
gun_Script.enabled = true;
rb.isKinematic = true;
coll.isTrigger = true;
slotFull = true;
}
}
void Update() {
Vector3 distanceToPlayer = player.position - transform.position;
if(!equipped && distanceToPlayer.magnitude <= pickUpRange && Input.GetKeyDown(KeyCode.E) && !slotFull) PickUp();
if(equipped && Input.GetKeyDown(KeyCode.Q)) Drop();
}
private void PickUp() {
equipped = true;
slotFull = true;
transform.SetParent(gunPosition);
transform.localPosition = Vector3.SmoothDamp(Vector3.zero, Vector3.zero, ref Velocity, SmoothTime);
transform.localRotation = Quaternion.Euler(new Vector3(-3.574f, 79.96f, -3.077f));
transform.localScale = new Vector3(99.99998f, 100f, 99.99998f);
rb.isKinematic = true;
coll.isTrigger = true;
gun_Script.enabled = true;
}
private void Drop() {
equipped = false;
slotFull = false;
transform.SetParent(null);
rb.isKinematic = false;
coll.isTrigger = false;
rb.velocity = player.GetComponent<Rigidbody>().velocity;
rb.AddForce(fpsCam.forward * dropForwardForce, ForceMode.Impulse);
rb.AddForce(fpsCam.up * dropUpwardForce, ForceMode.Impulse);
transform.localScale = new Vector3(150f , 150f, 150f);
float random = Random.Range(-1f, 1f);
rb.AddTorque(new Vector3(random,random,random) * 10f);
gun_Script.enabled = false;
}
}