Fixes to JUMP system.

avinationmerge
Kitto Flora 2010-09-02 21:51:19 +00:00
parent 35d6181b78
commit 16814dd8f1
3 changed files with 168 additions and 56 deletions

View File

@ -58,7 +58,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
private int m_animTickFall; private int m_animTickFall;
// private int m_animTickJump; // private int m_animTickJump;
public int m_animTickJump; // ScenePresence has to see this to control +Z force public int m_animTickJump; // ScenePresence has to see this to control +Z force
public bool m_jumping = false; // Add for jumping
public float m_jumpVelocity = 0f; // Add for jumping
private int m_landing = 0; // Add for jumping
/// <value> /// <value>
/// The scene presence that this animator applies to /// The scene presence that this animator applies to
/// </value> /// </value>
@ -141,9 +144,11 @@ namespace OpenSim.Region.Framework.Scenes.Animation
/// </summary> /// </summary>
public string GetMovementAnimation() public string GetMovementAnimation()
{ {
//Console.WriteLine("GMA-------"); //##
const float FALL_DELAY = 0.33f; const float FALL_DELAY = 0.33f;
const float PREJUMP_DELAY = 0.25f; //rm for jumping const float PREJUMP_DELAY = 0.25f;
const float PREJUMP_DELAY = 200f; // mS add for jumping
const float JUMP_PERIOD = 800f; // mS add for jumping
#region Inputs #region Inputs
AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags; AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
@ -177,8 +182,7 @@ namespace OpenSim.Region.Framework.Scenes.Animation
// Is the avatar trying to move? // Is the avatar trying to move?
// bool moving = (move != Vector3.Zero); // bool moving = (move != Vector3.Zero);
bool jumping = m_animTickJump != 0; // rm for jumping bool jumping = m_animTickJump != 0;
#endregion Inputs #endregion Inputs
#region Flying #region Flying
@ -187,6 +191,9 @@ namespace OpenSim.Region.Framework.Scenes.Animation
{ {
m_animTickFall = 0; m_animTickFall = 0;
m_animTickJump = 0; m_animTickJump = 0;
m_jumping = false; //add for jumping flag
m_jumpVelocity = 0f; //add for jumping flag
actor.Selected = false; //add for jumping flag
if (move.X != 0f || move.Y != 0f) if (move.X != 0f || move.Y != 0f)
{ {
@ -213,8 +220,10 @@ namespace OpenSim.Region.Framework.Scenes.Animation
#region Falling/Floating/Landing #region Falling/Floating/Landing
if (actor == null || !actor.IsColliding) // rm for jumping if (actor == null || !actor.IsColliding)
if ((actor == null || !actor.IsColliding) && !m_jumping) // add for jumping
{ {
//Console.WriteLine("FFL"); //##
float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; float fallElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f; float fallVelocity = (actor != null) ? actor.Velocity.Z : 0.0f;
@ -223,7 +232,8 @@ namespace OpenSim.Region.Framework.Scenes.Animation
// Just started falling // Just started falling
m_animTickFall = Environment.TickCount; m_animTickFall = Environment.TickCount;
} }
else if (!jumping && fallElapsed > FALL_DELAY) // else if (!jumping && fallElapsed > FALL_DELAY)
else if (!m_jumping && fallElapsed > FALL_DELAY) // add for jumping
{ {
// Falling long enough to trigger the animation // Falling long enough to trigger the animation
return "FALLDOWN"; return "FALLDOWN";
@ -234,6 +244,67 @@ namespace OpenSim.Region.Framework.Scenes.Animation
#endregion Falling/Floating/Landing #endregion Falling/Floating/Landing
#region Jumping // section added for jumping...
Vector3 vj = Vector3.Zero;
int jumptime;
jumptime = Environment.TickCount - m_animTickJump;
if ((move.Z > 0f) && (!m_jumping))
{
//Console.WriteLine("PJ {0}", jumptime); //##
// Start jumping, prejump
m_animTickFall = 0;
m_jumping = true;
actor.Selected = true; // borrowed for jmping flag
m_animTickJump = Environment.TickCount;
vj.Z = 0.35f;
m_jumpVelocity = 0.35f;
vj += actor.Velocity;
// #@ actor.Velocity = vj;
return "PREJUMP";
}
if(m_jumping)
{
if ( (jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding)
{
//Console.WriteLine("LA {0}", jumptime); //##
// end jumping
m_jumping = false;
actor.Selected = false; // borrowed for jumping flag
m_jumpVelocity = 0f;
m_animTickFall = Environment.TickCount;
return "LAND";
}
else if (jumptime > JUMP_PERIOD)
{
//Console.WriteLine("JD {0}", jumptime); //##
// jump down
vj = actor.Velocity;
vj.Z = 0f;
m_jumpVelocity = 0f;
// #@ actor.Velocity = vj;
return "JUMP";
}
else if (jumptime > PREJUMP_DELAY)
{
//Console.WriteLine("JU {0}", jumptime); //##
// jump up
m_jumping = true;
vj.Z = 10f;
m_jumpVelocity = 10f;
vj.X = actor.Velocity.X;
vj.Y = actor.Velocity.Y;
// #@ actor.Velocity = vj;
return "JUMP";
}
}
#endregion Jumping // end added section
#region Ground Movement #region Ground Movement
if (m_movementAnimation == "FALLDOWN") if (m_movementAnimation == "FALLDOWN")
@ -245,11 +316,26 @@ namespace OpenSim.Region.Framework.Scenes.Animation
} }
else if (m_movementAnimation == "LAND") else if (m_movementAnimation == "LAND")
{ {
float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f; // rm jumping float landElapsed = (float)(Environment.TickCount - m_animTickFall) / 1000f;
if ((m_animTickFall != 0) && (landElapsed <= FALL_DELAY)) int landElapsed = Environment.TickCount - m_animTickFall; // add for jumping
// rm jumping if ((m_animTickFall != 0) && (landElapsed <= FALL_DELAY))
/* Try change ##
if ((m_animTickFall != 0) && (landElapsed <= 500)) // add for jumping
return "LAND"; return "LAND";
*/
// NB if this is set too long a weird anim reset from some place prevents STAND from being sent to client
if ((m_animTickFall != 0) && (landElapsed <= 300)) // add for jumping
{
//Console.WriteLine("LAND"); //##
return "LAND";
}
else
{
//Console.WriteLine("STAND"); //##
return "STAND";
}
} }
/* This section removed, replaced by jumping section
m_animTickFall = 0; m_animTickFall = 0;
if (move.Z > 0f) if (move.Z > 0f)
@ -279,27 +365,28 @@ namespace OpenSim.Region.Framework.Scenes.Animation
{ {
// Not jumping // Not jumping
m_animTickJump = 0; m_animTickJump = 0;
*/
if (move.X != 0f || move.Y != 0f) // next section moved outside paren. and realigned for jumping
{ if (move.X != 0f || move.Y != 0f)
// Walking / crouchwalking / running {
if (move.Z < 0f) // Walking / crouchwalking / running
return "CROUCHWALK"; if (move.Z < 0f)
else if (m_scenePresence.SetAlwaysRun) return "CROUCHWALK";
return "RUN"; else if (m_scenePresence.SetAlwaysRun)
else return "RUN";
return "WALK";
}
else else
{ return "WALK";
// Not walking
if (move.Z < 0f)
return "CROUCH";
else
return "STAND";
}
} }
// rm for jumping else
else if (!m_jumping) // add for jumping
{
// Not walking
if (move.Z < 0f)
return "CROUCH";
else
return "STAND";
}
// end section realign for jumping
#endregion Ground Movement #endregion Ground Movement
return m_movementAnimation; return m_movementAnimation;
@ -311,15 +398,15 @@ namespace OpenSim.Region.Framework.Scenes.Animation
public void UpdateMovementAnimations() public void UpdateMovementAnimations()
{ {
m_movementAnimation = GetMovementAnimation(); m_movementAnimation = GetMovementAnimation();
if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump) /* if (m_movementAnimation == "PREJUMP" && !m_scenePresence.Scene.m_usePreJump)
{ {
// This was the previous behavior before PREJUMP // This was the previous behavior before PREJUMP
TrySetMovementAnimation("JUMP"); TrySetMovementAnimation("JUMP");
} }
else else
{ { removed for jumping */
TrySetMovementAnimation(m_movementAnimation); TrySetMovementAnimation(m_movementAnimation);
} // rm for jumping }
} }
public UUID[] GetAnimationArray() public UUID[] GetAnimationArray()

View File

@ -1471,6 +1471,9 @@ namespace OpenSim.Region.Framework.Scenes
if (actor.Flying != oldflying) if (actor.Flying != oldflying)
update_movementflag = true; update_movementflag = true;
if (m_animator.m_jumping) // add for jumping
update_movementflag = true;
if (q != m_bodyRot) if (q != m_bodyRot)
{ {
m_bodyRot = q; m_bodyRot = q;
@ -2580,6 +2583,7 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.Info("[AGENT]: Stop FLying"); // m_log.Info("[AGENT]: Stop FLying");
//} //}
} }
/* This jumping section removed to SPA
else if (!actor.Flying && actor.IsColliding) else if (!actor.Flying && actor.IsColliding)
{ {
if (direc.Z > 2.0f) if (direc.Z > 2.0f)
@ -2592,12 +2596,12 @@ namespace OpenSim.Region.Framework.Scenes
{ {
direc.Z *= 0.1f; // prejump direc.Z *= 0.1f; // prejump
} }
/* Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs / * Animations are controlled via GetMovementAnimation() in ScenePresenceAnimator.cs
Animator.TrySetMovementAnimation("PREJUMP"); Animator.TrySetMovementAnimation("PREJUMP");
Animator.TrySetMovementAnimation("JUMP"); Animator.TrySetMovementAnimation("JUMP");
*/ * /
} }
} } */
} }
// TODO: Add the force instead of only setting it to support multiple forces per frame? // TODO: Add the force instead of only setting it to support multiple forces per frame?
@ -3543,28 +3547,46 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
public override void UpdateMovement() public override void UpdateMovement()
{ {
if (m_forceToApply.HasValue) if (Animator!=null) // add for jumping
{ { // add for jumping
// if (!m_animator.m_jumping) // add for jumping
// { // add for jumping
Vector3 force = m_forceToApply.Value; if (m_forceToApply.HasValue) // this section realigned
m_updateflag = true; {
Velocity = force;
m_forceToApply = null; Vector3 force = m_forceToApply.Value;
} m_updateflag = true;
else if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
{ Velocity = force;
if (m_isNudging) //Console.WriteLine("UM1 {0}", Velocity);
{ m_forceToApply = null;
Vector3 force = Vector3.Zero; }
else
{
if (m_isNudging)
{
Vector3 force = Vector3.Zero;
m_updateflag = true; m_updateflag = true;
Velocity = force; if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
m_isNudging = false; Velocity = force;
m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND" //Console.WriteLine("UM2 {0}", Velocity);
} m_isNudging = false;
} m_updateCount = UPDATE_COUNT; //KF: Update anims to pickup "STAND"
} }
else // add for jumping
{ // add for jumping
Vector3 force = Vector3.Zero; // add for jumping
if (m_animator.m_jumping) force.Z = m_animator.m_jumpVelocity; // add for jumping
//Console.WriteLine("UM3 {0}", Velocity);
Velocity = force; // add for jumping
}
}
// } // end realign
} // add for jumping
} // add for jumping
/// <summary> /// <summary>
/// Adds a physical representation of the avatar to the Physics plugin /// Adds a physical representation of the avatar to the Physics plugin

View File

@ -90,6 +90,7 @@ namespace OpenSim.Region.Physics.OdePlugin
public float walkDivisor = 1.3f; public float walkDivisor = 1.3f;
public float runDivisor = 0.8f; public float runDivisor = 0.8f;
private bool flying = false; private bool flying = false;
private bool jumping = false; // add for jumping
private bool m_iscolliding = false; private bool m_iscolliding = false;
private bool m_iscollidingGround = false; private bool m_iscollidingGround = false;
private bool m_wascolliding = false; private bool m_wascolliding = false;
@ -229,7 +230,8 @@ namespace OpenSim.Region.Physics.OdePlugin
public override bool Selected public override bool Selected
{ {
set { return; } // set { return; }
set { jumping = value; } // add for jumping flag
} }
public override float Buoyancy public override float Buoyancy
@ -1018,7 +1020,8 @@ namespace OpenSim.Region.Physics.OdePlugin
{ // close, jump to lateral destination { // close, jump to lateral destination
d.BodySetPosition(Body, _zeroPosition.X, _zeroPosition.Y, pos.Z); d.BodySetPosition(Body, _zeroPosition.X, _zeroPosition.Y, pos.Z);
} }
if (flying) // if (flying)
if (flying || jumping) // add for jumping
{ {
vec.Z = (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P; vec.Z = (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
} }