- Home /
Question by
Peterpantsu · Mar 05, 2017 at 03:35 PM ·
c#movementrigidbodyvelocityprojectile
Convert rigidbody velocity to home in on target when it gets close
Hey, I'm having a bit of difficulty figuring something out with a projectile object.
The object originally gets launched and moves via rigidbody velocity.
I'm trying to find a way to keep that velocity and redirect it to slightly home in on the enemy if the object gets within a certain distance of an enemy as a form of aim assist.
Any tips or ideas? Any help at all would be much appreciated.
*Exact speed or close enough to.
example.png
(27.5 kB)
Comment
Answer by NecrosDk · Mar 06, 2017 at 04:44 PM
Check if your shuriken's Vector3.distance to the target object is within a threshold, and add a force to it that is equal to target.transform.position minus shuriken.transform.position, multiplied by whatever speed you want :)
Example of script on shuriken:
void Update(){
if(Vector3.Distance(transform.position, target.transform.position) < maxDistForAimAssist)){
GetComponent<Rigidbody>().AddForce((target.transform.position - transform.Position) * assistForce);
}
}