- Home /
gun problems
how can i make an object move from one point to another... like a bullet in a gun
               Comment
              
 
               
              Answer by $$anonymous$$ · Aug 06, 2012 at 12:44 PM
There are couple of ways to approach this. If you simply want to fire a bullet then the easiest would be to do the following.
 void Update()
 {
     Vector3 directionOfFire = Vector3.forward;
     float bulletSpeed = 10f;
     gameObject.transform.Translate(directionOfFire * Time.deltaTime * bulletSpeed);
 }
But if you want to move a bullet from one fixed point to another (which is not how it normally happens, but still might be a requirement in your game) the following might help you.
  private float m_DeltaTime = 0f;
  private Vector3   m_StartPos;
  private Vector3   m_EndPos;
  
  void Start()
  {
     m_StartPos = Vector3.zero;
     m_EndPos = Vector3.left * 100f;
  }
  
  void Update()
  {
     if(m_DeltaTime < 1f)
     {
        m_DeltaTime += Time.deltaTime;
        gameObject.transform.position = Vector3.Lerp(m_StartPos, m_EndPos, m_DeltaTime);
     }
  }
Your answer
 
 
             Follow this Question
Related Questions
gun problems 1 Answer
Bullets Based on Orientation 1 Answer
Making a bullet destroy itself on contact. 1 Answer
Shooting. Bullet floats and sprays 1 Answer
Troubles With A Shoot Script 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                