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 Tekbomber · Nov 14, 2013 at 07:17 AM · gun movement

Player control problems with gun script

I'm following a tutorial on how to make a fps game and i got all the movement stuff down but when it comes to the gun script part it messed everything up. In this video he can move around with the gun but when I copied everything he's done I can't move at all, the player capsule runs around but I'm stuck and can't move but i can look around and my gun is stuck too and it flashes and glitches out. I'll provide a youtube link to the part where I am at and stuck.

alt text

link text

game problem.jpg (257.1 kB)
Comment
Add comment · Show 7
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 Tekbomber · Nov 14, 2013 at 08:05 AM 0
Share

When I finish the the tutorial to the end of the video, I can get the gun to move around with the mouse look, but moving with W,A,S,D keys just makes the player capsule move around and not me, Im just stuck in a fixed position.

avatar image mattssonon · Nov 14, 2013 at 08:44 AM 0
Share

Is the camera a child of the capsule you're moving?

avatar image Tekbomber · Nov 14, 2013 at 08:57 PM 0
Share

Yes it is.

avatar image mattssonon · Nov 15, 2013 at 08:22 AM 0
Share

Can you post the code that reacts to key presses from W, A, S, and D? Are you restricting the movement of the camera in some way?

avatar image Tekbomber · Nov 15, 2013 at 08:22 PM 0
Share

This problem only started to happen after I added the gun script. I noticed that when I change the value of the hold height of the gun it changes the position of the camera too which is weird. $$anonymous$$aybe the gun has a collider mesh enabled that comes from Blender? I tried disabling it with a script and it allows me to move again but the gun stays anchored and doesn't move at all.

here is my player movement script

 var walkAccelRacio : float = 0.1;
 var walkDeacceleration : float = 5;
 @HideInInspector
 var walkDeaccelerationVolx : float;
 @HideInInspector
 var walkDeaccelerationVolz : float;
 var cameraObject : GameObject;
 var maxWalkSpeed : float = 20;
 @HideInInspector
 var horizontal$$anonymous$$ovement : Vector2;
 
 var jumpVelocity : float = 20;
 @HideInInspector
 var grounded : boolean = false;
 var maxSlope : float = 60;
 
 function Update () 
 {
 horizontal$$anonymous$$ovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
 if (horizontal$$anonymous$$ovement.magnitude > maxWalkSpeed)
 {
 horizontal$$anonymous$$ovement = horizontal$$anonymous$$ovement.normalized;
 horizontal$$anonymous$$ovement *= maxWalkSpeed;
 }
 rigidbody.velocity.x = horizontal$$anonymous$$ovement.x;
 rigidbody.velocity.z = horizontal$$anonymous$$ovement.y;
 
 if (grounded){
 rigidbody.velocity.x = $$anonymous$$athf.SmoothDamp(rigidbody.velocity.x, 0, walkDeaccelerationVolx, walkDeacceleration);
 rigidbody.velocity.z = $$anonymous$$athf.SmoothDamp(rigidbody.velocity.z, 0, walkDeaccelerationVolz, walkDeacceleration);
 }
 
 transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent($$anonymous$$ouseLookScript).currentYRotation, 0);
 if(grounded)
 
 rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical")* walkAcceleration * Time.deltaTime);
 else
 rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * walkAccelRacio * Time.deltaTime, 0, Input.GetAxis("Vertical")* walkAcceleration * walkAccelRacio* Time.deltaTime);
 
 if (Input.GetButton("Jump") && grounded)
 rigidbody.AddForce(0,jumpVelocity,0);
 }
 
 function OnCollisionStay (collision : Collision)
 {
 for (var contact : ContactPoint in collision.contacts)
 {
    if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
       grounded = true;
    }
 }
 function OnCollisionExit ()
 {
 grounded = false;
 
 }
Show more comments

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

FPS Techniques for Aim and Gun movement? 0 Answers

How to make gun sway script affect camera 1 Answer

How could i make my gun move where my cursor is? 1 Answer

Adding Ammo to make gun loose/add ammo as used/picked up 1 Answer

Sprint position for gun 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