- Home /
how to move object toward target without rotating it?
I have a plane object in game as bullet, i want to shoot that bullet but I cant rotate it because it is just a plane object with texture, but the game space is in 3D, how can i shoot that bullet toward player without rotating it? it doesnt have to be tracking the player's position, but just when first initiate the bullet, its direction has to be toward the target player without rotating it. Thanks very much!
You should post more info:
1- If your game is 2D, things move only in two axis - the 3rd one usually is kept at a constant value. Which are the main axes? X and Y? X and Z?
2- How do you plan to move the bullet? Rigidbody+AddForce or simply translate the bullet transform towards the target?
you can place a raycasthit on the enemies' weapons and check for distance: var hit : RaycastHit; var player : GameObject; //check to see if the enemy is shooting var isShooting : boolean = false; private var myTransfrom : Transform; var bullet : Rigidbody;
var distance : float = Vector3.Distance(player.transform.position - bullet.transform.position);
//make sure your player is tagged "Player"
if(hit.collider.gameObject.tag == "Player" && isShooting == true){
if(distance < 1){
//how much damage does the bullet make
doDamage(100);
}
}
/*of course that's not an entire code(there's still bullet instantiation etc...) but it should cover the basics plus the bullet never rotates hope it helps*/
Answer by Owen-Reynolds · Mar 02, 2013 at 03:53 PM
"Normal" bullet code says to aim at the player and then move along your current forwards. To skip the aiming step, just figure out what your forward line would have been if you were aiming, and shoot on that:
// WITH AIM:
//bullet.LookAt(target); // aiming
//bullet.rigidbody.velocity = bullet.forward*10; // push along my forwards
// NO AIM:
// figure which way LookAt would have aimed you:
Vector3 toTarg = (target.position - bullet.position).normalized;
// toTarg is now exactly what bullet.forwards would be if we aimed
bullet.rigidbody.velocity = toTarg*10;
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
shooting scripts 0 Answers
Projectile Shooting Problem 1 Answer
Combining meshes (different materials) together for rotation/translation 1 Answer
RotateAround Limitations 2 Answers