RigidBody2D Hovering not working some computer
Hello i make 2D Game and implemented hover effect(floating).
first my rigidbody2D component option is blew picture.
and I made the hover function work by pressing and holding the X button.
Below is the source I created.
void Update()
{
CheckJump();
CheckRavitate();
DoingAction();
}
void DoingAction()
{
if (this.IsStatus(CustomCharacterInfo.CHAR_STATUS.JUMP))
{
// Jump
this.rigid2D.AddForce(transform.up * JUMP_FORCE);
nowStatus &= ~CustomCharacterInfo.CHAR_STATUS.JUMP;
}
if (IsStatus(CustomCharacterInfo.CHAR_STATUS.RAVITATE))
{
RaycastHit2D rayHitData = Physics2D.Raycast(
new Vector2(transform.position.x, transform.position.y),
new Vector2(0, -1.0f),0.5f,
1 << GlobalLayerMask.TERRIAN_MASK);
bool canRavitate = rayHitData.collider ? false : true;
Debug.DrawRay(transform.position, new Vector2(0, -0.8f),Color.green);
if (canRavitate)
{
float yVel = Physics.gravity.y;
Debug.Log("Ravitae FORECE " + yVel);
//Howering
rigid2D.AddForce(new Vector2(0, -yVel), ForceMode2D.Force);
}
}
}
/*
My intention is that when the x key is pressed for more than 0.05 seconds,
the floating flag is turned on.
When you release x, it will be off.
*/
void CheckRavitate()
{
if (true)
{
if (Input.GetKey(KeyCode.X))
{
if (raviValue.canRavitate && Time.time - raviValue.tDown > 0.05f && rigid2D.velocity.y < 0.2f)
{
Debug.Log("RAVITATE FLAG ON");
nowStatus |= CustomCharacterInfo.CHAR_STATUS.RAVITATE;
rigid2D.velocity = new Vector2(0.0f, 0.0f);
raviValue.canRavitate = false;
}
}
if (this.IsStatus(CustomCharacterInfo.CHAR_STATUS.RAVITATE) && Input.GetKeyUp(KeyCode.X))
{
nowStatus &= ~CustomCharacterInfo.CHAR_STATUS.RAVITATE;
raviValue.canRavitate = true;
}
}
}
void CheckJump()
{
// Jump Function
if (Input.GetKeyDown(KeyCode.X) && jumpcount > 0)
{
isGrounded = false;
nowStatus |= CustomCharacterInfo.CHAR_STATUS.JUMP;
jumpcount--;
raviValue.tDown = Time.time;
}
}
public class RavitateFlag
{
public float tDown;
public bool canRavitate;
public RavitateFlag()
{
tDown = Time.time;
canRavitate = true;
}
}
that result below that
that was errormotion capture
that was correct motion capture
The issue does not floating work with the player's computer.
I do not know why this is the difference. The code is the same and the log is the same too.
If you change one gravitiscale to 1, floating function works normally.
But I think that this is not a solution. Also, when you change the gravity scale to 1, the character that was in normal operation will fly to the sky.
I guess it is time to call the update function, but this is also not clear.
Your answer
Follow this Question
Related Questions
Convert Keyboard controlls to UI Buttons 1 Answer
(2D Top Down Shooter, Unity2D) Creating a bullet trail effect? 0 Answers
Player Skins Won't Load 0 Answers
How to store max y position of object 0 Answers
unity2d One Scene Not Working 0 Answers