Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

How do i move in the direction i'm looking at

$
0
0
I don't know a lot about scripting, all i know is how to do make a simple movement script and a quit game script. I want to move in the direction I'm looking at but i don't know how to do it, can someone please help? Heres my script using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class PlayerController : MonoBehaviour { public Rigidbody Player; public Camera Camera; public Vector3 jump; public float jumpForce = 2.0f; public bool isGrounded; Rigidbody rb; void Start(){ rb = GetComponent(); jump = new Vector3(0.0f, 2.0f, 0.0f); Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } void OnCollisionStay(){ isGrounded = true; } // Update is called once per frame void Update() { if (Input.GetKey("d")) { Player.AddForce(4, 0, 0); } if (Input.GetKey("a")) { Player.AddForce(-4, 0, 0); } if (Input.GetKey("w")) { Player.AddForce(0, 0, 4); } if (Input.GetKey("s")) { Player.AddForce(0, 0, -4); } if (Input.GetKeyDown(KeyCode.Space) && isGrounded){ rb.AddForce(jump * jumpForce, ForceMode.Impulse); isGrounded = false; } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>