Question by
ARandomGuy90 · Apr 01, 2018 at 09:41 AM ·
playershootingplayer movement
How make the "player" shoot on the Y axis?
I can't figure out, please help :) Thank you!
( GetComponent().velocity.x); if activated, overrides the GetComponent().velocity.y);.. i can't understand what should i do )
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FireSphereController : MonoBehaviour {
public float speed;
public float speed2;
public PlayerController player;
// Use this for initialization
void Start () {
player = FindObjectOfType<PlayerController>();
if (Input.GetButton("LeftArrow"))
{
speed = -speed;
}
if (Input.GetButton("UpArrow") && GetComponent<Rigidbody2D>().velocity.y == 0)
{
GetComponent<Rigidbody2D>().velocity = Vector2.up * speed2 ;
}
}
// Update is called once per frame
void Update () {
GetComponent<Rigidbody2D>().velocity = new Vector2(speed, GetComponent<Rigidbody2D>().velocity.y);
GetComponent<Rigidbody2D>().velocity = new Vector2(speed2, GetComponent<Rigidbody2D>().velocity.x);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Collider")
{
Destroy(this.gameObject);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612155806im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add a jump key 2 Answers
Any ideas in relate to a cube rolling? thank you! 0 Answers
Reduce Player Movement in Air 0 Answers