Hi, I have a problem that is making me crazy… I have a 2D platform kind off game, where the user can only move on X and Y axis, well the thing is, Im moving the player with Physx
applying forces from a C# Scrip called PlayerMovement, I have two functions called Subir() and Bajar() (means up and down)
public void Subir()
{
if (!Atascado)
{
rigidbody.AddRelativeForce((Vector3.up * acelVert * Time.deltaTime) * 1.5f, ForceMode.Impulse);
print("subiendo a "+GetComponent<CharacterProperties>().Name);
if (detenido)
{
acelVert = 10;
}
if (!detenido)
{
acelVert += 50;
}
up = true;
}
}
public void Bajar()
{
if (!Atascado)
{
rigidbody.AddRelativeForce((Vector3.up * -acelVert * Time.deltaTime) * 1.5f, ForceMode.Impulse);
print("bajando a " + GetComponent<CharacterProperties>().Name);
if (detenido)
{
acelVert = 10;
}
if (!detenido)
{
acelVert += 50;
}
down = true;
}
}
now from the very PlayerMovement Script im calling those functions just like
if (Input.GetKey(KeyCode.DownArrow))
{
Bajar();
}
if (Input.GetKey(KeyCode.UpArrow))
{
Subir();
}
and it works Great! but from other side I have a C# script called GameBasics
from there Im drawning some GUITexture buttons and catching their inputs with the mouse position like this:
if (Input.GetMouseButtonDown(0))
{
if (turboBtn.HitTest(Input.mousePosition))
{
_pMovement.LanzaTurbo();
}
if (switchPlayerBtn.HitTest(Input.mousePosition))
{
SwitchPlayer();
}
}
if (Input.GetMouseButton(0))
{
if (upArrowBtn.HitTest(Input.mousePosition))
{
_jugador.GetComponent<PlayerMovement>().Subir();
}
if (dwnArrowBtn.HitTest(Input.mousePosition))
{
_jugador.GetComponent<PlayerMovement>().Bajar();
}
}
Now here’s the problem the first to “LanzarTurbo()” and “SwitchPlayer()” are working fine when I click the corresponding buttons on the screen, but when I click on the other two, apparently the Subir() and Bajar() functions are being called but no force is been applied to my character. I know Subir() and Bajar() works cause I printed some output on the console and I can see from both ways, with the Keyboard Arrows and with the GUITexture buttons, but the second ones arent really applying the force to my object, any ideas why this is happening? or any suggestions to solve that?
as you can see on the PlayerMovement Subir() and Bajar() functions I have a print() function that prints some output, output that can be seen through both ways, but the rigidbody.AddRelativeForce() is not reflecting any changes on my character with the function being called from other script.