Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class moveWarriorKnight : MonoBehaviour
- {
- public int speed; //We can change the speed value inside Unity because it is public
- public Rigidbody rb;
- public Vector3 velocity;
- public float m_Thrust = 20f;
- Vector3 Vec;
- // Start is called before the first frame update
- void Start()
- {
- rb.AddForce(velocity);
- }
- // Update is called once per frame
- void Update()
- {
- transform.Rotate(0, speed, 0); //Spins object on y axis
- Vec = transform.localPosition;
- //Vec.y += Input.GetAxis("Jump") * Time.deltaTime * 20;
- Vec.x += Input.GetAxis("Horizontal") * Time.deltaTime * 20;
- Vec.z += Input.GetAxis("Vertical") * Time.deltaTime * 20;
- transform.localPosition = Vec;
- }
- //For when the top collides with another
- public void OnCollisionEnter(Collision collisionInfo)
- {
- if (collisionInfo.collider.tag == "Layer")
- {
- //Grab the other object
- GameObject Other = collisionInfo.collider.gameObject;
- //Get the velocity from the other object
- Vector3 OtherVelocity = Other.GetComponent<Rigidbody>().velocity;
- //compare speeds
- if (rb.velocity.magnitude < OtherVelocity.magnitude)
- {
- // if speed < other add force away from winner position
- rb.AddForce(transform.up * m_Thrust);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement