Quantcast
Channel: Answers for "Making an arrow Physics without using rigid body"
Viewing all articles
Browse latest Browse all 6

Answer by skovacs1

$
0
0

EDIT: modified the math applied to drag to more closely reflect the Drag Equation by using velocity squared and some constant for the drag. Going any further would also involve calculating the Reynold's number component to determine the drag coefficient.

I'm not entirely sure from your description how you've decided to fire and initially orient ~100 arrows, so I'll make some assumptions and describe how I would approach this.

Why an arrow flies the way it does

An object is propelled with a force in some direction. Given an initial directional force, the object moves forward and encounters wind resistance (which an arrow's design should try to minimize) proportional to the velocity, which will slow the movement. The object in flight will also descend due to gravity. This generally forms the arc of a thrown object.

An arrow will turn along the arc of its trajectory with the arrowhead at the front of the motion because the arrow is heavier at the arrowhead (higher mass and therefore the arrowhead will be less affected by the force of wind resistance(drag) than the shaft). Because of the arrowhead's slightly greater acceleration towards the ground, it will pull the front of the shaft downwards and cause the arrow to rotate.

The feathers will also generate drag to provide stability to the arrow's path for an improvement in accuracy.

How to simulate this

moving the arrow is easy enough

//I forewent the transform.forward because that would only confuse things right now
static var gravity : Vector3 = Vector3.up * -9.81; //let's assume it's always down
var drag : float = 0.01; // A coefficient for the amount of drag in the medium
var velocity : Vector3; //The movement to make this contains direction and speed
private var moving : boolean = false;

function Update() {
    if(moving) {
        velocity += gravity;
        velocity -= velocity.sqrMagnitude * drag * velocity.normalized;
        transform.position += velocity * Time.deltaTime;
    }
}

Rotating it is only a little trickier. Essentially, we've calculated what direction to move in and we need to rotate so that forward is now that way. There are a bunch of ways to do this. I'll take the naive approach because it demonstrates what we're doing more easily:

static var gravity : Vector3 = Vector3.up * -9.81; //let's assume it's always down
var drag : float = 0.01; // A coefficient for the amount of drag in the medium
var velocity : Vector3; //The movement to make this contains direction and speed
private var moving : boolean = false;

function Update() {
    if(moving) {
        velocity += gravity;
        velocity -= velocity.sqrMagnitude * drag * velocity.normalized;
        var amountToMove = velocity * Time.deltaTime;
        transform.LookAt(transform.position + amountToMove); //look where you're going
        transform.position += amountToMove; //go there
    }
}

This is very rudimentary implementation overall, but generally covers everything that we really care about and does so fairly efficiently. By tuning the drag and setting the velocity when you fire, you can get any number of results you'd like that should follow physics fairly accurately. To add forces like wind, you would simply add them as another force like gravity however you like. I assume your down is always down, otherwise you would have to calculate gravity's effect every calculation. Note that terminal velocity here is when drag * (velocity + gravity) = gravity.

To get more meaningful results, I'd probably place the pivot at the tip or center of mass of the arrowhead, but that's your call.

You didn't mention how you were handling collisions, but either by doing your own raycast along transform.forward after you've rotated or using a Collider setup, it's fairly easy to simply stop moving.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>