- Home /
Question by
Bokaii · Jul 15, 2014 at 07:11 PM ·
rigidbodymultiplayerfirst person shooter
Rigidbody add force problem
So I have this rigid body first person controller, (I have it so I can pounce like in the game "The Hidden") (Pounce = launch in cameras direction)
I have it so it launches in the direction of the Camera, but it only launches a little bit forward, and then up! Why does it do that, and is there a way to fix it? :)
Code:
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
public float Force = 1500;
public bool wallSitting = false;
public bool grounded = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonUp("Fire3")){
rigidbody.AddForce(transform.FindChild("Camera").TransformDirection(Vector3.forward) * Force);
}
if(wallSitting == true){
rigidbody.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationY;
}
else{
rigidbody.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
}
}
void OnCollisionStay(Collision col){
if(col.gameObject.tag == "Test"){
if(Input.GetButtonDown ("Fire3")){
wallSitting = !wallSitting;
}
}
grounded = true;
}
void OnCollisionExit(){
grounded = false;
}
}
Comment
Are you also using the default FPS controller on this GameObject?
No, I am using the FPSWalker, you can find somewhere on google :P
FPSWalker (using c#) http://wiki.unity3d.com/index.php?title=RigidbodyFPSWalker