math - How do I calculate impact force between two 2D objects in Unity 3D -


i working on 2d space shooter game , make player ship movements directly transform of ship , not via physics (so no addforce here). make player ship bounce of asteroids hits using build in physics won't work movement code uses transform directly, figured should make simple physics calculations self , add calculated force movement force use on transform. way go?

but can not figure out how make correct calculations force, can guys me out here? simple idea angle between player ship , asteroid , convert angle vector , add resulting force vector movement force. work , how do it? or there better way?

i have added image illustrate idea (the idea can not figure out how make calculations for), circle asteroid, triangle ship, dotted triangle ship movement , collision force added, green line movement force (always forward/up), red line illustrates angle player ship asteroid , blue line collision force. makes sense?

also how calculate correct angle , force vector angle? struggle math :( have tried angle , create force vector angle in following code. not take real force account try direction , normalize make fixed size, , apply ship position test math , see if vector in right direction, not. can guys me also?

vector2 tovector = othercollider.transform.position - transform.position; float angletotarget = vector2.angle(transform.position, tovector); vector3 anglevelocity = new vector3((float)mathf.cos(angletotarget), (float)mathf.sin(angletotarget), 0); anglevelocity = anglevelocity.normalized * 1.0f;  transform.position = transform.position + anglevelocity;

enter image description here

thank you
søren

the angle of ship in relation asteroid give velocity x , y axis. use 1 point in level origin (0, 0). can treat each object dot make life simple.

you can calculate force using newton's laws of motion. focus on second law.

f = ma

which means force equals mass times acceleration. have give mass object , find out how acceleration each object has instant before impact.

you have given objects velocity instead of acceleration. can use kinematics.

v_f^2 = v_i^2 + 2*a*d

v_f final velocity.

v_i initial velocity.

d distance object has traveled.

a acceleration.


or maybe momentum easier you.

p = m v


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -