Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by vorksholk · Jun 24, 2012 at 05:56 PM · fpsfps controller

FPS Gun Moves Weird When FPS Controller Turns up or Down

Thank you for your time :)

So basically I wanted to make a simply FPS, and I am currently using the object and texture from the FPS tutorial to give my game a Rocket Launcher. I'll put in my own graphics for guns, but I want to get the basic framework working :)

I went through most of the FPS tutorial, but had an issue with some assets that it said were in "Standard Assets" not being there. Regardless, I got the rocketlauncher attached to the FPS nicely. However, when I tried importing the rocketlauncher mesh and texture, it looked fine. I tried dragging it to child it to my FPS controller's camera. I saw a problem people were having this was due to them childing the gun to the controller instead of the camera, but this doesn't appear to be my problem. If someone wants I'd be happy to post a screenshot of what it's doing if it's unclear. Basically the gun moves away from the player when your First Person Controller looks up, and back when your controller looks down, leading to a lot of distortion. Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dev Solo · Jun 24, 2012 at 09:46 PM

I'd say start from scratch if you're having troubles with it. It should only take 30 seconds to load in a new FPS controller and attach a gun to its camera.

The only thing I can imagine to explain that is if you might have added a "mouse look" script to the gun as well as the camera.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vorksholk · Jun 25, 2012 at 01:57 PM 0
Share

Tried making a new project and it worked! However, I did figure out what my problem is, but I don't know how to fix it... I have a script attached to my FPS controller, and somehow these things which affect FOV, etc. are also affecting the gun and distorting it. Here is the code, might you be able to point out what's wrong? This code's a compilation of a few other answers and solutions found around the forum, by the way.

var walkSpeed: float = 7; // regular speed var crchSpeed: float = 3; // crouching speed var runSpeed: float = 20; // run speed var walkFOV: float = 60; var runFOV: float = 65; var current: float = 0; private var ch$$anonymous$$otor: Character$$anonymous$$otor; private var tr: Transform; private var dist: float; // distance to ground

function Start(){ ch$$anonymous$$otor = GetComponent(Character$$anonymous$$otor); tr = transform; var ch:CharacterController = GetComponent(CharacterController); dist = ch.height/2; // calculate distance to ground }

function Update(){

 var vScale = 1.0;
 var speed = walkSpeed;
 
 if (ch$$anonymous$$otor.isGrounded && Input.Get$$anonymous$$ey("left shift") || Input.Get$$anonymous$$ey("right shift") || Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift)){
     speed = runSpeed;
     current = 1;
 }
 else
 {
 speed=walkSpeed;
 current = 0;
 }
 if (Input.Get$$anonymous$$ey("c")){ // press C to crouch
     vScale = 0.5;
     speed = crchSpeed; // slow down when crouching
     current=-1;
 }
 else
 {
 vScale=1.5;
 }
 if (current == 1)
 {
 
     if (Camera.main.fieldOfView < runFOV)
     {
     Camera.main.fieldOfView=Camera.main.fieldOfView+1.5;
     }
 }
 else
 {
 if (Camera.main.fieldOfView > walkFOV)
     {
     Camera.main.fieldOfView=Camera.main.fieldOfView-1.5;
     }
 }
 ch$$anonymous$$otor.movement.maxForwardSpeed = speed; // set max speed
 var ultScale = tr.localScale.y; // crouch/stand up smoothly 
 tr.localScale.y = $$anonymous$$athf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
 tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position

}

avatar image Dev Solo · Jun 25, 2012 at 09:40 PM 0
Share

One thing I notice is that you use else { if.

"else if" can be written as such, and in this particular case it should be just "else" ... ( if Camera.main.fieldOfView was equal walkFOV it would do nothing at all)

Try organizing your script with more comments for future notice, but for now just post a new question regarding the details, since I wouldn't personally know where to begin.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Player Falls Much Slower While Moving 2 Answers

Physic Based FPS Movement,Fps Movement Physic Based 0 Answers

Vive Controller not enabled until mouse click 0 Answers

I need help with adding double jump to my player movement script 0 Answers

How to know the speed of my FPS controller? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges