2D Toolkit Forum
2D Toolkit => Support => Topic started by: stevexu on September 26, 2013, 04:25:04 pm
-
I have a tk2dSprit with a Rigidbody attach to it,
When I move a Rigidbody using this script:
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
moveTowardRight();
}
void moveTowardRight()
{
cleanFlag(STATE_STANDBY);
cleanFlag(STATE_RUN_LEFT);
addFlag(STATE_RUN_RIGHT);
Vector3 vy = rigidbody.velocity.y * (hasFlag(STATE_JUMP) ? Vector3.up : Vector3.zero);
rigidbody.velocity = vy + Vector3.right * SPEED;
}
it does go forward but has a decreased gravity, so it looks like it floats but when I release the key that makes my rigidbody move it drops down way faster. All the settings of my rigidbody are default so why does this happen ??
-
Don't know, but where are you calling moveTowardRight from?
-
In FixedUpdate.
I checked, the rigidbody.velocity .y is always 0 , and the Physics.gravity is always -9.8, and nobody collid with rigidbody
void FixedUpdate()
{
// rigidbody.WakeUp();
detectKey();
updateAniByState();
System.Diagnostics.Debug.Assert(rigidbody.position.z == -0.5);
print("rigidbody.velocity = " + rigidbody.velocity + " rbody = " + rigidbody);
}
void detectKey()
{
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
moveTowardRight();
}
else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
// rigidbody.transform.Translate(Vector3.left * SPEED * Time.deltaTime);
moveTowardLeft();
}
-
I'm not sure what else to suggest - I've not tried this before.