Question by
SwxerSwxerson · Oct 02, 2016 at 05:38 AM ·
2d gametopdownrpg
2D topdown RPG shooting in facing direction
I am complete beginner in C# coding and I need to make topdown RPG games for my project. I've used this video as a reference https://www.youtube.com/watch?v=8aVZuL9ocrk The only problem I faced is getting to shoot projectiles based on where my character is facing (up, down, left and right). My character only shoots to the right, I am clueless and I don't know what to do :( This is the coding i've done so far for my projectiles.
using UnityEngine;
using System.Collections;
public class FireballController : MonoBehaviour {
public float speed;
public Rigidbody2D theRigidbody;
public PlayerMovement player;
// Use this for initialization
void Start()
{
theRigidbody = GetComponent<Rigidbody2D>();
player = FindObjectOfType<PlayerMovement>();
}
// Update is called once per frame
void Update()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(speed, GetComponent<Rigidbody2D>().velocity.y);
}
void OnTriggerEnter2D(Collider2D other)
{
Destroy(gameObject);
}
}
Comment