- Home /
Question by
ontech7 · Dec 06, 2014 at 07:04 PM ·
c#projectileplatform
Projectile Y-axis start position issue - 2.5D Platform
I have this issue and I can't fix it. I've already tried to search on internet but I found nothing. The "projectile spawn" is situated next to my character. When I left-click on my mouse, the projectile starts shooting going forward (in the Z-axis at 20 speed, for example) but there is this issue that is making me mad. Sometimes it starts from the right place, sometimes under and under every click.
EDIT: I'm at home and this is the "shoot code". Thank you in advance.
public Rigidbody projectile;
public float speed = 20;
private Transform spawnPoint;
private int SPAWN_DISTANCE = 1;
void Awake()
{
spawnPoint = transform.Find("SpawnPoint");
}
void Update ()
{
//
if (Input.GetButtonDown("Fire1"))
{
atkSpeed = 0.2f;
Shoot(projectile);
attackTime = atkSpeed;
chargeLevel = 0;
}
//
}
void Shoot(Rigidbody proj){
Rigidbody _projBody = Instantiate(proj, spawnPoint.position + SPAWN_DISTANCE * transform.forward, transform.rotation) as Rigidbody;
_projBody.velocity = transform.TransformDirection(new Vector3(0, 0,speed));
}
HERE IS THE VIDEO: https://www.youtube.com/watch?v=GLgrfl2zU9w
EDIT2: SOLVED!
Comment
Your answer
Follow this Question
Related Questions
Problem with player movements 1 Answer
How to make specific text in a string array Bold C# 2 Answers
Movement Script Help 1 Answer
C# Plane Detecting a Gameobject 1 Answer