Advertisement
MysteryGM

Unity_Beyblade

Jun 15th, 2021
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class moveWarriorKnight : MonoBehaviour
  6.  
  7. {
  8.     public int speed; //We can change the speed value inside Unity because it is public
  9.     public Rigidbody rb;
  10.     public Vector3 velocity;
  11.     public float m_Thrust = 20f;
  12.  
  13.     Vector3 Vec;
  14.  
  15.     // Start is called before the first frame update
  16.     void Start()
  17.     {
  18.         rb.AddForce(velocity);
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.  
  25.         transform.Rotate(0, speed, 0); //Spins object on y axis
  26.         Vec = transform.localPosition;
  27.  
  28.         //Vec.y += Input.GetAxis("Jump") * Time.deltaTime * 20;
  29.         Vec.x += Input.GetAxis("Horizontal") * Time.deltaTime * 20;
  30.         Vec.z += Input.GetAxis("Vertical") * Time.deltaTime * 20;
  31.         transform.localPosition = Vec;
  32.     }
  33.  
  34.     //For when the top collides with another
  35.  
  36.     public void OnCollisionEnter(Collision collisionInfo)
  37.     {
  38.         if (collisionInfo.collider.tag == "Layer")
  39.         {
  40.             //Grab the other object
  41.             GameObject Other = collisionInfo.collider.gameObject;
  42.             //Get the velocity from the other object
  43.             Vector3 OtherVelocity = Other.GetComponent<Rigidbody>().velocity;
  44.  
  45.             //compare speeds
  46.             if (rb.velocity.magnitude < OtherVelocity.magnitude)
  47.             {
  48.                 // if speed < other add force away from winner position
  49.                 rb.AddForce(transform.up * m_Thrust);
  50.             }
  51.  
  52.         }
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement