Question by
Valnus · Jun 01 at 06:17 PM ·
transformrotate objectfire
Projectile problem
Hi
I need some help please.
So I have a gun and a bullet scripted and linked. If I fire the projectile it only works one way.
When I fire any other direction the bullet unnaturally rotates and drifts to one direction.
Gun Logic :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunLogic : MonoBehaviour
{
[SerializeField]
GameObject m_bulletPrefab;
[SerializeField]
Transform m_bulletSpawnPoint;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
if (m_bulletPrefab && m_bulletSpawnPoint)
{
Instantiate(m_bulletPrefab, m_bulletSpawnPoint.position, m_bulletSpawnPoint.rotation * m_bulletPrefab.transform.rotation);
}
}
}
}
Bullet Logic :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletLogic : MonoBehaviour
{
Rigidbody m_rigidbody;
float m_bulletSpeed = 10.0f;
// Start is called before the first frame update
void Start()
{
m_rigidbody = GetComponent<Rigidbody>();
if (m_rigidbody)
{
m_rigidbody.velocity = transform.up * m_bulletSpeed;
}
}
}
untitled.png
(519.4 kB)
Comment