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: