- Home /
Survival Shooter- How do I add FPS and Jump Option?
Hello, I'm new to new Unity, I have completed the survival shooter tutorial but I want to add fps and jump option. I have used the fps script from character but I keep getting error. I have attached the camera to a player but its not very efficient. How can I be able to add fps and jump function? Please help, thank you!
Answer by chillersanim · Oct 06, 2016 at 08:56 AM
Hello.
The fps script from character depends on other scripts from the same asset.
Make sure to import ALL content from that bundle.
For the jump function:
You can use the Input class to determine the pressed buttons.
If the button of your choosing is pressed, you can apply an upward force to the player rigidbody.
I would reccomend the Impulse mode and quite some force.
You need to try different force values in order to find one that fits for you.
Example:
public float JumpForce;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
var rigid = this.gameObject.GetComponent<Rigidbody>();
if (rigid != null)
{
rigid.AddForce(transform.up * JumpForce, ForceMode.Impulse);
}
}
}
Note: It should work, but I haven't tested my code.
So if I made a mistake, please let me know.
Greetings
Chillersanim
I have added that to the player movement script given in tutorial and I have tried creating a separate jump script and the player still doesn't jump. No errors are showing up and for fps i get crossplatfor$$anonymous$$put errors? Do i need to import that asset as well? Thanks!
Does your player have a rigidbody?
If so, is it set to kinematik?
Answer by Rumannoodles · Oct 07, 2016 at 07:42 AM
Yes, I got it. Now stuck on jumping :/. Thanks for your awesome help!
Do you use the default FirstPerson player script?
It provides it's own jump function and does not work together with physics that well..
Otherwise, could you post a screenshot of your player gameobject (inspector setup) and your player code?
Your answer
Follow this Question
Related Questions
Saving Depth buffer for VR Game on Unity - DROP IN FPS 1 Answer
Bouncy platforms/spring jump? 4 Answers
standard fps walking script makes me faster when jumping 0 Answers
Raycasting 1 Answer
Issues after updating to Unity 5 1 Answer