- Home /
When Movement speed Change once it never change again
So I'am making A game and iam using a ball with a Rigedbody3D on it on the fixed update of the ball/player there is this code
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMove : MonoBehaviour {
public float MovementSpeed;
public float MovementSpeedForOthers;
[SerializeField]
private float SidesMovmentSpeed = -40f;
public Vector3 DirForWord;
public Vector3 DirLeft;
public Vector3 DirRight;
public Vector3 DirDown;
void FixedUpdate()
{
DirForWord = new Vector3(0, 0, MovementSpeed );
DirLeft = new Vector3(SidesMovmentSpeed, 0, 0);
DirRight = new Vector3(-SidesMovmentSpeed, 0, 0);
// this.GetComponent<Rigidbody>().velocity = DirForWord * Time.deltaTime;
this.GetComponent<Rigidbody>().AddForce(DirForWord * Time.deltaTime, ForceMode.Impulse);
if (Input.GetKey(KeyCode.A))
{
this.GetComponent<Rigidbody>().AddForce(DirRight * Time.deltaTime, ForceMode.Impulse);
}
if (Input.GetKey(KeyCode.D))
{
this.GetComponent<Rigidbody>().AddForce(DirLeft * Time.deltaTime, ForceMode.Impulse);
}
}
}
and Iam using a another 2 scripts called Player_booster And Player_Slower The Point is the Player_booster change the MovmentSpeed in the Playermove script to * 2 And the Player_Slower Do movmentSpeed/2 and both of these scripts going to change the speed back to normal after 1 sec but the proplme of this when one of the Slower or Booster scripts worked on the player let say the player ran the slow script his speed gonna be devided by 2 and get back to normal after 1 sec but if he ran the boost script after that his speed get multiplied by 2 normily but he doesnt go faster at all for some reason I tried all the forces mode but none worked I think this is a unity glitch or something please if you have an idea of the fix comment becuase I dont think Iam able to fix this by my own and sorry for bad spelling Cant help it.
Answer by williamclarks · Nov 02, 2020 at 03:05 PM
My friends and I decided on a similar case. Then the problem was with the web hosting provider. Maybe now you need to contact technical support?
It's strange that it didn't work, and I also don't understand why.
Your answer
Follow this Question
Related Questions
How can I move with UI buttons without having to press many times? 2 Answers
add force to object that has 2 different rigid bodies 0 Answers
Force is being added to wrong RigidBody 1 Answer
How to make rigidbodies on each side of a cube fall towards the cube? [multiple gravity / addForce] 0 Answers
Rigidbody.velocity seems to be breaking jumping physics 0 Answers