- Home /
Projectile Firing High
So I'm new to Unity and following tutorials as I go, but I'm having trouble spawning the projectiles correctly. Here's the spawning script: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class SpawnProjectiles : MonoBehaviour
{
public GameObject firePoint;
public List<GameObject> vfx = new List<GameObject>();
public CameraY cameraY;
private GameObject effectToSpawn;
void Start()
{
effectToSpawn = vfx[0];
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
SpawnVFX();
}
}
void SpawnVFX()
{
GameObject vfx;
if (firePoint != null)
{
Debug.Log(firePoint.transform.position.y);
vfx = Instantiate(effectToSpawn, firePoint.transform.position, Quaternion.identity);
vfx.transform.localRotation = cameraY.GetRotation();
}
else
{
Debug.Log("No Fire Point");
}
}
}
It seems to also be colliding with the move script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class PlayerMove : MonoBehaviour
{
[SerializeField] float speed = 6.0f;
[SerializeField] float jumpSpeed = 8.0f;
[SerializeField] float gravity = 20.0f;
[SerializeField] float sensitivity = 3;
private Vector3 moveDirection = Vector3.zero;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivity, 0);
}
}
When the player is moving around, the projectile spawns at the set spawn point just fine, and when the playermove script is disabled it spawns from there. However, when the player is still, it spawns about 3 units up, which when the playermove script is disabled, the player jumps up to, no matter the transformation coordinates. I can't figure out what would be causing it, so I was hoping someone with more experience could help me. If there's anything more you need let me know.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do i Achieve mesh Extrusion? 2 Answers
Can I make a collider ignore only one other collider? 0 Answers
knockback 3d c# 1 Answer