You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

56 lines
1.1 KiB

using UnityEngine;
using System.Collections;
public class P2_weapon : MonoBehaviour {
public float pushMagnitude = 500;
void Start () {
renderer.enabled = false;
}
void Update (){
if (Input.GetKeyDown (KeyCode.Space)) {
// show
renderer.enabled = true;
collider2D.enabled = true;
}
if (Input.GetKeyUp (KeyCode.Space)){
renderer.enabled = false;
collider2D.enabled = false;
}
}
void OnCollisionEnter2D (Collision2D col){
Vector2 ab = new Vector2 (0, 0);
//pushmagntiude
if (col.gameObject.name == "Cube") {
//Get a and b
Vector2 a;
Vector2 b;
a = transform.position;
b = col.transform.position;
//Calculate AB->
ab = b - a;
Debug.Log (ab);
//Modify to add height
ab = new Vector2 (ab.x,ab.y +0.8f);
Debug.Log (ab);
//Normalise AB
ab.Normalize();
Debug.Log (ab);
//Multiple AB by push magnitude
ab = ab * pushMagnitude;
Debug.Log (ab);
//Push opponent by AB * magnitude
col.gameObject.rigidbody2D.AddForce (ab, ForceMode2D.Force);
col.gameObject.GetComponent<PlayerControler>().Pushed();
}
}
// Update is called once per frame
}