The question is answered, right answer was accepted
**Trying to make a shield that slows downs bullets when bulletes enter**
Bullet tag: Bullet and shield tag: BulletTimeShield
hey i have tryed so many things and i really need help!
like i said at the top im trying to make a shield that slows the bulletes as they are going in and speeds up to normal speed when they exit
i have tried rigidbody drag and Oncollisionenter and exit but thats not working
i really hope that some one can help me
thanks for reading and your time
So it's like when you activate your shield the bullets will reduce its speed . Is that what you meant. I'm just clarifying things.
more when i Activate it and a bullet flys in to it :) ps its a 3d game :)
B = Bullet
( ) <----B Bullet normal speed ( B ) Slow bullet <-----B ( ) Normal Speed :P
Answer by meat5000 · Jan 19, 2018 at 02:00 PM
OnCollisionEnter, access via GetComponent the rigidbody of the object. Store the current velocity value. Reduce it by percentage or fraction and restore it OnCollisionExit
This may not work as expected due to discrepencies in the Collision Detection of fast moving objects.
However, as you imply the object should move through, you will probably need to use OnTrigger functions instead.
Edit : Ok, on large objects it seems that this approach only works while planes are intersecting. However, this following method will work but may be a little intensive. Its a little rough and has drawbacks specifically with multiple objects, but its for the illustration of a working method.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SlowObject : MonoBehaviour {
Vector3 tempTriggerVelocity;
Rigidbody otherRB;
float scaler = 0.1f;
void OnTriggerEnter(Collider other)
{
otherRB = other.gameObject.GetComponent<Rigidbody>();
tempTriggerVelocity = otherRB.velocity;
}
void OnTriggerStay(Collider other)
{
otherRB.velocity = tempTriggerVelocity * scaler;
}
void OnTriggerExit(Collider other)
{
other.gameObject.GetComponent<Rigidbody>().velocity = tempTriggerVelocity;
}
}
aah thank you so much! :P i did the trick! :P i totaly forgot about ontrigger event :)
Answer by Husnain_ · Jan 18, 2018 at 05:14 AM
make a gameObject i.eBulletSpeedHandler that handle all bullet speed. make a static float speed variable here so that every bullet can get speed from here. and make sure u are using speed like this
transfrom.translate(BulletSpeedHandler.speed*vector2.whateverDirection)
now in the shield you need to reduce/increase the value of speed simply ,sdsf
so if its a 3d game i can do
transfrom.translate(BulletSpeedHandler.speed*vector3.Forward)??
Follow this Question
Related Questions
How can I make a collider that gives me stat up to stop giving me it? 0 Answers
OnCollisionEnter Problem 1 Answer
Drawing a GUI line 0 Answers