- Home /
The question is answered, right answer was accepted
Cant get arrow to stick
I can't get the arrows to stick, they collide properly with everything. I just can't seem to figure out how to get it to stick now.
There are two scripts one is for managing the arrows and the other for firing.
ArrowManagerScript
private void Fire(float strDist)
{
currentArrow.transform.parent = null; //detach arrow from all parants
Rigidbody r = currentArrow.GetComponent<Rigidbody>();
r.velocity = currentArrow.transform.forward * arrowPowerMultiplyer * strDist;
r.useGravity = true;
r.isKinematic = false;
stringAttachPoint.transform.localPosition = stringStartPoint.transform.localPosition; //rest string
currentArrow.GetComponent<Arrow>().Fired();
currentArrow.GetComponent<Collider>().isTrigger = false;
Destroy(currentArrow, 4f);
currentArrow = null;
isAttached = false;
}
ArrowScript
public bool isFired = false;
// Update is called once per frame
void Update()
{
if (isFired)
{
transform.LookAt(transform.position + transform.GetComponent<Rigidbody>().velocity);// make arrow lookat where it is going like an arrow
}
}
public void Fired()
{
isFired = true;
}
private void OnTriggerStay(Collider col)
{
if (SteamVR_Actions._default.GrabPinch.GetStateDown(SteamVR_Input_Sources.RightHand)) //if trigger pulled
{
ArrowManager.Instance.AttachArrowToBow(); //attach arrow to bow
}
}
I am hoping to get the arrow to stick, Also the arrow script is attached to an arrow prefab and the arrowmanager is attached to the SteamVr rightHand
Try using fixed update rather than update. You should always do your physics calculation in fixed update.
The other alternative is try using raycast and position to deter$$anonymous$$e if your arrow is in front of your target or back. so if it has passed the target you can manually stick it to the target.
Answer by tormentoarmagedoom · May 17, 2019 at 08:21 AM
Hello.
I did not read the code, but the solution is so simple.
Just need to detect when the arrow touched the objective, and then just need to make te objective parent of the arrow!
Arrow.transform.parent = Objective.transform;
Bye!
Answer by Aonex · May 17, 2019 at 12:20 PM
@tormentoarmagedoom Thank for the response :). I have tried implementing this and it still seems not to detect the collision between the arrow and target. I made sure to disable the trigger when the arrow is fired as well. I also tried making two game objects and comparing if they hit one another with no avail.
hi so i been doing the same just the other day, and all i did was after the hit, i set the arrows rigidbody to kinetic and parent it to other.(assu$$anonymous$$g its scale is 1,1,1)
Follow this Question
Related Questions
OVR Grabbable causes object to ignore OnCollisionEnter/Exit 2 Answers
Sword slashing logic on Gear VR using controller? 0 Answers
Destroy object after time Only if raycast is colliding; 0 Answers
Ignore Collisions with SteamVR Teleport Area? 1 Answer
Object possibly registering too many collisions with player (VR) 0 Answers