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

addForce problem please help!

$
0
0
![alt text][1] [1]: /storage/temp/65988-pic.png hello , i making a tutorial for fps game , like movement and jumping . im useing addForce to make jump like the tutorial but instead of jumping ith teleporting to the point and falls by gravity. note: im not useing character controller, i create an empty gameobject (like somes tutorials) with camrea as a child. and rigidbody,boxcollider,and my script attach to gameobject. i know this question has asked before ,but i did everything. please see the code ignore the rotation and movment . using UnityEngine; using System.Collections; public class characterControllerScript : MonoBehaviour { public float movmentSpeed = 10f; public float mouseSensetivity = 2.5f; public float verticalRotationRange = 60f; public float jumpForce = 50f; private float VerRotation = 0f; private double gravity = 0f; private float timer = 0f; // Use this for initialization void Start () { Cursor.visible = false; } // Update is called once per frame void Update () { timer += Time.deltaTime; //characterMovment+mouseDirection,depending the mouse facing to so the movment is. float horSpeed = Input.GetAxis("Horizontal")*movmentSpeed; float verSpeed = Input.GetAxis("Vertical")*movmentSpeed; float horRotation = Input.GetAxis("Mouse X") * mouseSensetivity; transform.Rotate(0, horRotation, 0); VerRotation -= Input.GetAxis("Mouse Y") * mouseSensetivity; VerRotation = Mathf.Clamp(VerRotation, -verticalRotationRange, verticalRotationRange); GetComponentInChildren().transform.localRotation=Quaternion.Euler(VerRotation,0,0); // Camera.main.transform.localRotation = Quaternion.Euler(VerRotation, 0, 0); // Debug.Log(VerRotation); Vector3 speed = new Vector3(horSpeed, 0, verSpeed); Rigidbody myRG = GetComponent(); speed = transform.rotation * speed; myRG.velocity = new Vector3(speed.x,speed.y,speed.z); //jumping if (Input.GetKeyDown(KeyCode.Space)) { GetComponent().AddForce(Vector3.up * jumpForce, ForceMode.Impulse); } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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