animation script behaving differently after build and run on a different computer.
ANSWER: I'm an idiot that forgot to include Time.deltaTime in my position update statement. -_- sorry for bothering all of you.
how I should have wrote the statement:
derp.transform.position += derp.transform.TransformDirection(Vector3.up) * (1f/50)*derp.GetComponent<playerScriptWithAnimation>().jumpForce * Time.deltaTime;
I have a script attached to my jump animation that is suppose to move my character upward while in that animation state. It works if I run it in unity or on the same computer I am using to make it but all other devices(laptops, computers) seem to have an issue. I have tried searching for an answer online but either I am using the wrong words or I can't find it. Also, I didn't find any errors in the output_log.txt and my other animation scripts work excpet the one I have for moving has the character moving oddly slower. Just a few guessing of mine(Time.deltaTime works differently after build, TransformDirection may work differently after build)
here is a link to download the desktop version of the game: http://www.mediafire.com/download/covx5745l0w67ib/Fire_Emblem_Fan-Made_Fighting_Game_v0.0.2_Data.zip
Below is the one line of code in question:
derp.transform.position += derp.transform.TransformDirection(Vector3.up) * (1f/2000)*derp.GetComponent<playerScriptWithAnimation>().jumpForce;
Here are other questions I feel are related to mine to show I'm not the only one experiencing this: http://answers.unity3d.com/questions/801610/camera-does-not-follow-player-after-build.html http://answers.unity3d.com/questions/745397/mouse-look-not-working-after-build.html http://answers.unity3d.com/questions/894555/transform-bug-only-happening-in-compiled-build.html
Below is the whole Script:
using UnityEngine;
using System.Collections;
using System.IO;
public class animationJump : StateMachineBehaviour {
public GameObject derp;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (animator.GetInteger ("playerNumber") == 1 &&
GameObject.FindGameObjectWithTag ("player1")) {
derp = GameObject.FindGameObjectWithTag ("player1");
} else if (animator.GetInteger ("playerNumber") == 2 &&
GameObject.FindGameObjectWithTag ("player2")) {
derp = GameObject.FindGameObjectWithTag ("player2");
} else if (animator.GetInteger ("playerNumber") == 3 &&
GameObject.FindGameObjectWithTag ("player1assist")) {
derp = GameObject.FindGameObjectWithTag ("player1assist");
} else if (animator.GetInteger ("playerNumber") == 4 &&
GameObject.FindGameObjectWithTag ("player2assist")) {
derp = GameObject.FindGameObjectWithTag ("player2assist");
} else {
Debug.LogError("wut");
}
derp.GetComponent<playerScriptWithAnimation> ().characterState = "jump";
derp.GetComponent<Rigidbody> ().useGravity = false;
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (derp == null) {
if (animator.GetInteger ("playerNumber") == 1 &&
GameObject.FindGameObjectWithTag ("player1")) {
derp = GameObject.FindGameObjectWithTag ("player1");
} else if (animator.GetInteger ("playerNumber") == 2 &&
GameObject.FindGameObjectWithTag ("player2")) {
derp = GameObject.FindGameObjectWithTag ("player2");
} else if (animator.GetInteger ("playerNumber") == 3 &&
GameObject.FindGameObjectWithTag ("player1assist")) {
derp = GameObject.FindGameObjectWithTag ("player1assist");
} else if (animator.GetInteger ("playerNumber") == 4 &&
GameObject.FindGameObjectWithTag ("player2assist")) {
derp = GameObject.FindGameObjectWithTag ("player2assist");
} else {
Debug.LogError ("wut");
}
}
derp.transform.position += derp.transform.TransformDirection(Vector3.up) * (1f/2000)*derp.GetComponent<playerScriptWithAnimation>().jumpForce;
if (animator.GetInteger("XSpeed") == 1) {
/*derp.GetComponent<Rigidbody> ().AddForce (derp.transform.forward * (-1.5f) * derp.GetComponent<playerScriptWithAnimation> ().movementForce);
if (Mathf.Abs (derp.GetComponent<Rigidbody> ().velocity.x) > derp.GetComponent<playerScriptWithAnimation> ().maxMovementSpeed) {
derp.GetComponent<Rigidbody> ().velocity = new Vector3 (derp.GetComponent<playerScriptWithAnimation> ().maxMovementSpeed * (derp.GetComponent<Rigidbody> ().velocity.x / Mathf.Abs (derp.GetComponent<Rigidbody> ().velocity.x)),
derp.GetComponent<Rigidbody> ().velocity.y,
derp.GetComponent<Rigidbody> ().velocity.z);
}*/
derp.transform.position += derp.transform.TransformDirection(Vector3.forward) * (-1f/100) * derp.GetComponent<playerScriptWithAnimation>().movementForce;
} else if (animator.GetInteger("XSpeed") == -1) {
/*derp.GetComponent<Rigidbody> ().AddForce (derp.transform.forward * 2f * derp.GetComponent<playerScriptWithAnimation> ().movementForce);
if (Mathf.Abs (derp.GetComponent<Rigidbody> ().velocity.x) > derp.GetComponent<playerScriptWithAnimation> ().maxMovementSpeed) {
derp.GetComponent<Rigidbody> ().velocity = new Vector3 (derp.GetComponent<playerScriptWithAnimation> ().maxMovementSpeed * (derp.GetComponent<Rigidbody> ().velocity.x / Mathf.Abs (derp.GetComponent<Rigidbody> ().velocity.x)),
derp.GetComponent<Rigidbody> ().velocity.y,
derp.GetComponent<Rigidbody> ().velocity.z);
}*/
derp.transform.position += derp.transform.TransformDirection(Vector3.forward) * (1f/100) *derp.GetComponent<playerScriptWithAnimation>().movementForce;
}
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (derp != null){
derp.GetComponent<playerScriptWithAnimation> ().characterState = "stand";
if(derp.GetComponent<playerScriptWithAnimation>().mount != null)
{
derp.GetComponent<playerScriptWithAnimation>().mount.GetComponent<Animator>().SetBool("Moving",false);
derp.GetComponent<playerScriptWithAnimation>().mount.localEulerAngles = new Vector3(0f,45f,0f);
}
}
derp.GetComponent<Rigidbody> ().useGravity = true;
}
}
Answer by orangeflame · Dec 30, 2015 at 06:19 PM
ANSWER: I'm an idiot that forgot to include time.deltaTime in my position update statement. -_- sorry for bothering all of you.
how I should have wrote the statement:
derp.transform.position += derp.transform.TransformDirection(Vector3.up) * (1f/50)*derp.GetComponent<playerScriptWithAnimation>().jumpForce * Time.deltaTime;
Your answer
Follow this Question
Related Questions
Unity windows build exit before asset import 0 Answers
Object position doesnt change in Build but does in Scene/Editor Game 0 Answers
Error when trying to use classes "UnityEditor.PlayerSettings" and "UnityEditor.AspectRatio" 0 Answers
Error when building in WebGL: "UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors" 0 Answers