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 /
avatar image
0
Question by ThunderbirdX11 · Nov 01, 2012 at 09:30 PM · animationweaponparentingstutterwalk

Character movement distorted when holding weapon

Hello everyone,

Here is my problem:

I have a player and a weapon. If the player walks or runs around without the weapon, he is able to run normal.

If the weapon is attached to the player, he walks a bit left with every animation loop and stutters when running with the weapon, but walking backwards (with S-Key) is possible without a distortion. It's pretty weird...

You can see it for yourself here: Webplayer

Try to run or walk directly to a destination without and then with the weapon

Controls:

  • Walk = W

  • Run = W + R

  • Walk backwards = S

The weapon has a box collider component, wich is controlled by the item_pickup script and switched off when the weapon gets parented.

Item-pickup is written to parent the weapon to the weaponmount-Empty in the right hand and to disable the weapons box collider component.

What I tried so far:

  • I can only prove the colliders innocence for this behaviour. It gets disabled when you grab the weapon, but the stutters are still there.

Here is the item_pickup script (attached to the player)

 var clone : GameObject;
 var Player : GameObject;
 
 var item_name;
 var WeaponHand : GameObject;
 
 var showGUI = false; 
 
 WeaponHand = GameObject.FindWithTag("weaponmount"); //The Tag of The Empty that's parented to the right Hand
 Player = GameObject.FindWithTag("Player");
 
 function OnTriggerStay (other : Collider) {
     if (other.gameObject.tag == "weapon"){
         
         showGUI = true;    
         item_name = other.gameObject.name;
         
         if (Input.GetKeyUp ("e")){
         
             clone = GameObject.Find(item_name);  //Find name of the Item we are colliding with
         
             clone.transform.parent = WeaponHand.transform;
             clone.transform.position = WeaponHand.transform.position;
             clone.transform.rotation = WeaponHand.transform.rotation;
             clone.collider.enabled = false;
             showGUI = false;
             Debug.Log("Parented !");        
             }
         
         }
     }    
         function OnGUI(){
             if (showGUI){
                 GUI.Label (Rect (500,500,1000,1000), "[E] Waffe aufnehmen"); //"Press E to Pickup the Weapon"
             }
            
           }


Here is also my walk-script (also attached to the player):

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof(CharacterController))]
 
 public class walk : MonoBehaviour {
     public float moveSpeed = 8;
     public float Strafespeed = 2.5f;
     public float rotateSpeed = 250;
     public float runspeed = 16;
 
     private Transform _myTransform;
     private CharacterController _controller;
     
             
     public void Awake(){
         _myTransform = transform;
         _controller = GetComponent<CharacterController>();
     }
     
     // Use this for initialization
     void Start () {
     animation.wrapMode = WrapMode.Loop;
 
     }
     
     // Update is called once per frame
     void Update () {
         DontDestroyOnLoad (this);
         Turn();
         move();
         attack();
 }
     
     private void Turn(){
                 if(Mathf.Abs(Input.GetAxis("Rotate Player")) > 0){
             _myTransform.Rotate(0, Input.GetAxis("Rotate Player") * Time.deltaTime * rotateSpeed, 0);
     }
 }
     
         private void move(){
         
             
             if(Mathf.Abs(Input.GetAxis("Move Forward")) > 0){
     
                 animation.CrossFade("walk", 0.2f);
                 _controller.SimpleMove(_myTransform.TransformDirection(Vector3.forward) * Input.GetAxis("Move Forward") * moveSpeed);
             
             if(Mathf.Abs(Input.GetAxis("run")) > 0 && Mathf.Abs(Input.GetAxis("Move Forward")) > 0){
                                 
                                 animation.CrossFade("run", 0.2f);
                                 _controller.SimpleMove(_myTransform.TransformDirection(Vector3.forward) * Input.GetAxis("run") * runspeed);
                         }
             }
             
             if(!(Input.anyKey)){
                     
                 animation.CrossFade("idle", 0.2f);
                 
             }    
     }
     private void attack(){
                 
                         if(Input.GetMouseButtonDown(0)){
                                 //Debug.Log ("Klick");
                                 animation.wrapMode = WrapMode.Once;
                                 animation.CrossFade("attack2", 0.2f);
                                 return;
             
                                 
                         }
             
                 }
     
     
 
     }
 
 

Here are the properties of my player character:

alt text

Comment
Add comment · Show 4
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 Owen-Reynolds · Nov 01, 2012 at 10:54 PM 0
Share

As you note, a little stutter and wiggle left (is the weapon in your right hand?) is exactly what an active collider childed to a charController does.

I'd pause the scene when you know it's stuttering, and take another look for colliders (does the weapon have child colliders?)

avatar image Montraydavis · Nov 02, 2012 at 12:55 AM 0
Share

Can you post a screen shot of the collider gizmos active ? Like @Owen Reynolds said, it probably has to do with colliders.

avatar image Montraydavis · Nov 02, 2012 at 12:56 AM 0
Share

Set the weapon Collider as Trigger, and see if that makes a difference. If so, it definitely has to do with the Sword physics colliding the your players physics. Happens to me sometimes.

avatar image ThunderbirdX11 · Nov 02, 2012 at 05:02 AM 0
Share

The weapon has a Box Collider by default, it gets deactivated when the player grabs it. The Box Collider is a trigger by default:

http://pn.dyna-studios.com/TA-Problemdemo/555.JPG

Here is the situation after it got parented to the character:

http://pn.dyna-studios.com/TA-Problemdemo/666.JPG

I totally removed the collider component for a test and continued gameplayback. The error is still there.

http://pn.dyna-studios.com/TA-Problemdemo/777.JPG

If it has to do something with the collider, then why does the character not slide to the right whe he is movig backwards? I mean it is the same animation, only played backwards and the same weapon that is in the same positions.

It is only stutterig when I move the character forward.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ThunderbirdX11 · Nov 02, 2012 at 07:53 PM

OK I found the reason:

After I created an empty object and parented it as a "weapon" with no strange behavior afterwards, I came to think the weapon mesh is the reason for the issue. Although I deactivated "create mesh colliders" in the .fbx-Import, the childobject of the imported-Object had a mesh-collider component activated.

I removed it and now everything works fine :)

Thx

Comment
Add comment · 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
0

Answer by Owen-Reynolds · Nov 02, 2012 at 02:00 PM

For a test, try shrinking the gun collider away from the part the player grabs, so there's a wider gap between it and the player while holding it. If that changes nothing, it wasn't the collider.

Some explanation: char controllers only "own" their built-in capsules. If they have other colliders childed to them, unlike regular physics, they don't know that they own them. When charCons move, they treat child colliders as solid, immovable objects, same as all other rigid bodies (they can't even push them, since they never push anything.)

After the char controller is done smashing and sliding against a child "obstacle," parenting moves the child. To the char controller, it looks like some idiot keeps moving a wall in front of it.

Moving backwards, even if the gun animation clips it a little, the char is moving away from that obstacle, into open space, so isn't blocked.

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 ThunderbirdX11 · Nov 02, 2012 at 02:22 PM 0
Share

I have also tried to leave some space between the collider and the weapon but it doesn't change anything. As soon as it gets parented, the stutter-effect is there again. Seems like it isn't a collider-issue. But what else could it be?

avatar image Owen-Reynolds · Nov 02, 2012 at 05:37 PM 0
Share

Bracket it. Try having the "weapon" be just an empty, and the code only child it. See if that causes it (probably won't.) Then add more until it stutters. Likewise, keep removing parts of the weapon and commenting out code until the error stops.

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

11 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

Related Questions

Attaching Weapon to Animated Character 0 Answers

Photon: Trembling Player 1 Answer

Custom Weapon Animation 2 Answers

Animated Child Snapping to Parent's Coordinates 1 Answer

Changing specific animation of a person 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