0
\$\begingroup\$

Object A is moving via. 2D rigidbody by velocity V and in script is defined breaking power P. Every frame of breaking (P * Time.deltaTime) is subtracted from velocity V (in other words, ignoring mass). How i can calculate distance D required to slow down to target velocity tV ?

I'm not actually using force/power but i setting velocity directly with this line of code :

Vector3 dir = transform.TransformDirection(Vector3.up);
ship.rb.velocity = Vector2.MoveTowards(ship.rb.velocity, (dir * maximalSpeed) * ship.massModifier, speedGain / ship.massModifier);
(Don't worry about ship.massModifier, Basically heavier ship hulls are slower)

I'm self-learning Indie developer and i need this for AI to my game. Enemy in space ship have nothing like space-breaks so only way how to slow down is to turn ship by 180 degrees and thrust forward in counter-direction.I need to know this to calculate distance from target required to slow down and prevent possible collision with target.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Use the formula

$$ t = \frac{v_0}{a}$$

$$ s = v_0 \cdot t + \frac{at^2}{2}$$

where \$v_0\$ is the starting velocity, \$a\$ is the acceleration/deceleration and \$s\$ is the distance

\$\endgroup\$
6
  • \$\begingroup\$ "where v0 is the starting velocity, a is the acceleration/deceleration and s is the distance" And what about target velocity ? @Bálint \$\endgroup\$ Commented Feb 7, 2018 at 16:28
  • \$\begingroup\$ @Garrom in that case use (v0/v1)/a when calculating t, where v1 is the end speed \$\endgroup\$ Commented Feb 7, 2018 at 16:33
  • \$\begingroup\$ So i must use 't= (v0/v1)/a' instead 't = v0/a' , right ? And one more thing, "t" is time what whole breaking/accelerating takes , right? \$\endgroup\$ Commented Feb 7, 2018 at 16:39
  • \$\begingroup\$ @Garrom Yeah, that's it \$\endgroup\$ Commented Feb 7, 2018 at 16:42
  • \$\begingroup\$ Just one last thing.I know this is stupid question but I was in special class and teacher refused to teach me stuff like this no matter of level of my intellect. "at" means a+t or a*t ?I know this is very basic knowledge but my math teacher was a jerk... \$\endgroup\$ Commented Feb 8, 2018 at 12:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.