Movement worked yesterday but doesn't anymore? I did not make any changes in script
Just as the question says - yesterday, my game worked smoothly. The player was moving nicely. Here is a gif showing how it used to move! alt text
Here is my simple movement script:
public class Movement : MonoBehaviour {
public float playerSpeed = 5.0f;
public float smooth = 5.0f;
public float tiltAngle = 90;
public float speed;
void Start ()
{
//player spawns here
transform.position = new Vector3(385, 0, 318);
}
// Update is called once per frame
void Update (){
Physics.gravity = new Vector3(0, -120f, 0);
if(Input.GetKey(KeyCode.W)){
transform.Translate(0,0,5*Time.deltaTime);
// Rotate the cube by converting the angles into a quaternion.
transform.rotation = Quaternion.Euler(0, -90, 0);
}if(Input.GetKey(KeyCode.S)){
transform.Translate(new Vector3(0,0,5)*Time.deltaTime);
transform.rotation = Quaternion.Euler(0, 90, 0);
}if(Input.GetKey(KeyCode.D)){
transform.Translate(0,0,5*Time.deltaTime);
// Rotate the cube by converting the angles into a quaternion.
transform.rotation = Quaternion.Euler(0, 0, 0);
}if(Input.GetKey(KeyCode.A)){
transform.Translate(new Vector3(0,0,5)*Time.deltaTime);
// Rotate the cube by converting the angles into a quaternion.
transform.rotation = Quaternion.Euler(0, 180, 0);
}
}
}
I did not change anything in the script since yesterday. However, for some reason, the chicken doesn't move anymore today. See the gif with today's chicken:
I have no idea why this is happening today. But, clearly, my animation script still works, my jump script works, my camera rotation & zoom in/out script works too.
I will add my chicken's Inspector bar in an answer below.
I find it so strange that what was once working yesterday, doesn't anymore! Any response what be greatly appreciated. Thanks.
UPDATE - I found that when I disable my Jump script, the chicken walks again, with or without Character controller! So, I think my Jump script it causing my $$anonymous$$ovement script to not work?
But I have no idea why...
Here is my Jump script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : $$anonymous$$onoBehaviour
{
public Animator anim;
private CharacterController controller;
private float verticalVelocity;
private float gravity = 14f;
private float jumpForce = 5.0f;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input. Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
anim.Play("Run In Place");
}
if (Input. Get$$anonymous$$eyUp($$anonymous$$eyCode.Space))
{
anim.Play("Idle");
}
if(controller.isGrounded){
verticalVelocity = -gravity * Time.deltaTime;
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
verticalVelocity = jumpForce;
}
} else {
verticalVelocity -= gravity * Time.deltaTime;
} Vector3 moveVector = new Vector3 (0,verticalVelocity,0);
controller.$$anonymous$$ove(moveVector * Time.deltaTime);
}
}
Please I'd really appreciate some help with this! Its been driving me nuts!
Thank you.
Answer by pebblechan · Nov 14, 2019 at 07:06 AM
Screenshot of chicken's Inspector panel.
I found when I toggle off "Character Controller", the chicken moves again but not as smoothly as it used to yesterday. Character Controller was on yesterday though so I'm not sure if that is the issue?!
Answer by goutham12 · Nov 14, 2019 at 09:08 AM
why you are change gravity that to in update. and also you are using character controller.
refer this links copy the whole script and give a try
https://docs.unity3d.com/ScriptReference/CharacterController.Move.html
https://docs.unity3d.com/ScriptReference/CharacterController.SimpleMove.html
Hey thanks for your reply! I am also not sure why
Physics.gravity = new Vector3(0, -120f, 0);
is in update. I'm still new to Unity and tried to keep my script as simple as possible so that I understand all the elements.
This line may have been something I added for a different purpose. In any case, I removed that line and yet still have the same problem -- the chicken doesn't move! :( So, that line is not the issue.
Thanks for the links but I'd prefer to get to the root of this problem and not try other scripts because like I said, this script was working perfectly yesterday...
Your answer
Follow this Question
Related Questions
Can't move camera parent from child script with camera on timeline movement 0 Answers
Moving forward seems to be specific to the original direction of the object being controlled 0 Answers
My 2d movement script isn't working 0 Answers
Unusual movement script. Any ideas how to do that? 0 Answers
Limit movement to just forward/backward and left/right 0 Answers