Hello the problem is as topic says the bullets shooted flys in difrent direction as they should so maybe some profesional unity developer could help me solve this out trying to this whole day and im out of ideas…
Shooting & movment script:
using UnityEngine;
using System.Collections;
public class characterMovment : MonoBehaviour {
#region --Pubs--
public bool Run {
get
{
return _run;
}
set
{
_run = value;
}
}
public GameObject ammo;
public string weaponName = "H&K";
public int weaponMinDmg = 4;
public int weaponMaxDmg = 15;
public float moveSpeed = 6.0F;
public float runSpeed = 9.0F;
public float gravity = 20.0F;
#endregion
#region --Privs--
private bool _run;
private Vector3 _moveDirection = Vector3.zero;
#endregion
// Use this for initialization
void Start () {
Run = false;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.T))
{
if(_run)
{
Run = false;
}
else
{
Run = true;
}
}
CharacterController controller = GetComponent<CharacterController>();
if(controller.isGrounded)
{
_moveDirection = new Vector3(0,0,Input.GetAxis("Vertical"));
_moveDirection = transform.TransformDirection(_moveDirection);
if(!_run)
{
_moveDirection *= moveSpeed;
}
else
{
_moveDirection *= runSpeed;
}
}
_moveDirection.y -= gravity*Time.deltaTime;
controller.Move(_moveDirection*Time.deltaTime);
transform.RotateAround(new Vector3(0,Input.GetAxis("Horizontal"),0)*Time.deltaTime,Time.deltaTime);
if(Input.GetKeyDown(KeyCode.F))
{
Instantiate(ammo,transform.position,transform.rotation);
}
}
}
Bullet fly script:
using UnityEngine;
using System.Collections;
public class bulletMove : MonoBehaviour {
#region --Pubs--
public int bulletRange = 10;
public float bulletSpeed = 4;
#endregion
#region --Privs--
private Vector3 startPos;
private GameObject shooter;
#endregion
// Use this for initialization
void Start () {
shooter = GameObject.FindGameObjectWithTag("Player");
startPos = shooter.transform.position;
}
// Update is called once per frame
void Update () {
float distance = Vector3.Distance(startPos,transform.position);
Debug.Log(distance);
float move = bulletSpeed * Time.deltaTime;
transform.Translate(transform.forward * move);
if(distance >=bulletRange)
{
Destroy(gameObject);
}
}
}