last day (14 days later) » 

9:47 AM
0
A: OnCollisionEnter2D making my object to disappear from game screen

k4rlssontransform.LookAt is rotating your go which makes you unable to see it. try rotating it like this instead : Vector3 dir = selectedTarget.position - transform.position; float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

 
the bullets are just coming out ,not moving toward the enemy.,is there any problem in the bullets?
is there any way to control the speed of the turrets aiming movement?
 
Is this the original problem with the turret disappearing or another problem?
 
its another problem with bullet.,and why the transform.LookAt didnt worked?
 
If you dont want the turret to just flip to its proper direction you can turn it by lerping. (Vector2.Lerp()). This should be done from fixedupdate, when facing the target you can then fire your shot.
transform.lookat rotates the object around all axises which you probably dont want to do if you have a 2d game.
 
but my bullet is not moving forward,i have instantiated the code in the turret class.
 
9:47 AM
Please consider marking the question as an answer if it solved your problem and open a new question regarding how to turn the tower bit by bit.
 
can u help me with the bullet code
 
Your bullet is not moving since you apply a very small force, do you want your bullet to move at a constant speed?
 
yes
because i have made it a child of turret
and want to shoot it from the bulletSpwan object which is the chil of turret,its an empty object,so that where i can shoot from
 
try using a constantforce instead of rigidbody2c.addforce docs.unity3d.com/Manual/class-ConstantForce.html
 
ok,i will see to it,the force,but the current object i have placed,why it aiming in the enemy direction,rather than just pointing at it
so here lookAt works right for 3d?
 
9:56 AM
what do you mean by here? can you paste some example code
 
the turret should exactly point towards the enemy.
its the problem with the speed movemet?
 
doesnt the turret point towards the enemy?
 
it just look a little ahead of the enemy.
looks*
its not pin-point looking at enemy
means exactly
is there any way to control it?
 
 
2 hours later…
12:02 PM
Vector3 lookPos = new Vector3(bulletSpawn.position.x,bulletSpawn.position.y,0);
lookPos = lookPos - transform.position;
float ang = Mathf.Atan2(lookPos.y,lookPos.x)*Mathf.Rad2Deg;
GameObject b1 = Instantiate(bulletPrefab,new Vector3(transform.position.x,transform.position.y,5),transform.rotation)as GameObject;
b1.rigidbody2D.velocity = new Vector3(Mathf.Cos(ang*Mathf.Deg2Rad),Mathf.Sin(ang*Mathf.Deg2Rad),0)*bulletSpeed;
hey got it ,i just calculated the bulletSpawn position and the transform disstance and spawned the bullet
 

last day (14 days later) »