Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by OrganizedChaos · Jan 09, 2016 at 01:05 AM · c#camerafps

I have a problem with making a first person shooter

Ok so this is my first question I've posted. I'm trying to do a quick build of a first person shooter to get a functioning product done as I haven't really finished anything. So I'm not focussing too much on quality as that's what gets me caught up in production.

Anyway my problem:

So it's sort of two part. My first problem, which won't exactly be a problem later, but it could be: I made guns out of cubes to start coding, and so I didn't have to sit and code a holding block I just made it a child of my camera, and positioned it at the hold position. This is working fine but for some reason when I look up and down the gun warps weirdly. I'll try to attach some screenshots.

The next problem is I've written a block of code for switching guns. It works perfect for certain guns, but once I get to the first gun I've made it runs the DropGun() function on the gun I'm trying to pick up and keeps the one I already have. Also when I continuously try to pick up the gun, it warps them also. I've also found it's when I have my camera faced down where the gun I'm holding is warped. Any help would be greatly appreciated. I'm not a beginner to coding or using unity (however I wouldn't say I'm a strong coder), but this is a problem I can't figure out. This will help me learn a bunch.

here are the picking up and dropping functions Let me know if you need to see any other code:

void Pickup() { if (pControl.currentGun != null) { Firearm arm; arm = pControl.currentGun.GetComponent(); arm.DropGun(); }

     Debug.Log("I'm getting picked up");
     gameObject.transform.parent = cam;
     body.isKinematic = true;
     body.useGravity = false;
     collider.enabled = false;
     transform.localPosition = holdPosition;
     transform.localRotation = Quaternion.identity;
     isHeld = true;
     pControl.currentGun = gameObject;
 }

 public void DropGun()
 {
     gameObject.transform.parent = null;
     body.isKinematic = false;
     body.useGravity = true;
     collider.enabled = true;
     body.AddForce(Player.transform.forward * throwPower);
     isHeld = false;
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by OrganizedChaos · Jan 15, 2016 at 08:52 PM

Just an Update: I figured out the problem with the warping guns. I had had the camera as a child of my capsule, and I scaled it up (I'm using each unit as 1meter) which also scaled the camera up in the y axis. This caused some unwanted effects. So incase anyone else has experienced the same problem.

Still working on my weapon switch script. I'm sure I'll figure it out eventually.

Comment
Add comment · Show 1 · 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 wolfgangmami · Mar 20 at 01:55 AM 0
Share

2021 user here and I was suffering too. Your answer game me an idea. Don't change transforms of parent of the camera. But change camera's position and collider etc etc

avatar image
0

Answer by ParadoxSolutions · Jan 09, 2016 at 02:37 AM

 void Pickup() { if (pControl.currentGun != null) { Firearm arm; arm = pControl.currentGun.GetComponent(); arm.DropGun(); }

I think when you run Pickup() you run DropGun() at the same time so the gun you try to pick up immediately gets dropped, I can't be sure unless I know what the script is attached to. I am not sure what pControl is but you could try setting pControl.currentGun = null; then set pControl.currentGun equal to the weapon you are trying to pick up.

Make sure the two guns have different names other than both being called gameObject I say this because I don't see gameObject being set to the guns (assuming that's a gun).

I hope I am making sense I have not answered many questions, try running DropGun() first then PickupGun() to make sure you are setting the gameObjects parent to null.

Just a few things to try, Hope this helped.

Comment
Add comment · Show 4 · 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 OrganizedChaos · Jan 10, 2016 at 07:26 AM 0
Share

Thanks for the answer!

I'll review my code with your suggestions. The code I posted is from my parent firearm script. The children of this script are attached to the respective guns. I initially created a pistol out of cubes, and then to test the weapon switching, I created a shotgun and an assault rifle. What I was going for in the code you posted was to access the script of the weapon currently being held, then run that object's drop function. The code I have now allows me to pick up the pistol, switch to the shotgun, and then to the assault rifle. The pControl is a reference to the Player script attached to the player.

Also you wouldn't happen to know why the child objects of the main camera are warping when it's rotated up and down when looking? I plan to have the weapons coded to be held without being a child of the camera, but should I need to later. This isn't the first time this has been a problem.

Thanks again!

avatar image ParadoxSolutions OrganizedChaos · Jan 10, 2016 at 04:54 PM 0
Share

I have never had the problem with objects warping when a child of a camera, I would really need a picture to understand this; is the cube gun stretching? Do you have any Unity Pro image affects applied? $$anonymous$$ake sure you aren't using fisheye.

If you are doing this as a hobby or just to have a base understanding of FPS mechanics, I have seen an asset on the asset store that was using cube guns with various settings for projectiles/fx ect I can't remember the name though, if you want I can try and find a link for you.

If you are making a commercial game though I would highly recommend you invest into this package, it will save you thousands of hours in development time: https://www.assetstore.unity3d.com/en/#!/content/2943

avatar image OrganizedChaos ParadoxSolutions · Jan 12, 2016 at 07:58 AM 0
Share

alt text

I attached two screenshots. First one is it being warped or stretched, and the second one is neutral, how it's supposed to look. I only have Unity 5 standard, so I don't have any pro features. How do I know if fisheye is on? I also just figured out how to use rendering effects, so I can now add another layer of polish to my productions. So thank you. I played around with the ones in standard assets for about 20 $$anonymous$$s.

That looks like a cool plugin. I'm just a hobbyist. I'm kinda just having fun doing this, and I'm creating all my content myself so I don't have to spend any money. The price of that plug in is a little steep, but I do have FPS control which is very similar. But it seems to not work or something.

screen-shot-2016-01-12-at-25100-am.png (497.0 kB)
screen-shot-2016-01-12-at-25217-am.png (481.7 kB)
Show more comments

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

68 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Partial synchronization of camera with the bone of the head or other object 0 Answers

C# Camera based Recoil 0 Answers

i am making a 3D parkour fps game but i am stuck on fps camera and parkour movement i tried every tutorial but it didnt worked idk to make it because im new in programing so can someone help me plz? 0 Answers

Recoil system 0 Answers

Networking Fps Cameras 0 Answers


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