Having problems working with rotating platforms
by Vishal Bhanderi · in Torque X Platformer Kit · 12/20/2007 (5:32 am) · 1 replies
Guys im having trouble with the methods ActorLeft and ActorLanded. They don't seem to work when the actor is on the platform, and when he is off it, it goes mad and carries on spining. I checked the ActorOn variable and it stays to true even though the actor has left the platform.
The object is meant to tilt when the actor lands on it. I'm hoping there is a work around to this problem.
Thanks the help guys.
/// <summary>
/// A platform behavior that makes the platform tilt sideways when an actor sets on it.
/// </summary>
[TorqueXmlSchemaType]
class TiltPlatformBehavior : PlatformBehavior, ITickObject
{
//======================================================
#region Public properties, operators, constants, and enums
[TorqueXmlSchemaType(DefaultValue = "6")]
public float Tilt
{
get { return _tiltSpeed; }
set { _tiltSpeed = value; }
}
[TorqueXmlSchemaType(DefaultValue = "6")]
public float MaxTilt
{
get { return _maxTilt; }
set { _maxTilt = value; }
}
#endregion
//======================================================
#region Public methods
public override void ActorLanded(ActorComponent actor)
{
base.ActorLanded(actor);
//When it lands wiegh up what's on the platform and see what side to tilt
_actorOn = true;
_actor = actor.Actor;
//T2DAnimatedSprite animSprite = Owner as T2DAnimatedSprite;
//if (animSprite != null && !_fallTriggered)
//{
// animSprite.PlayAnimation(_triggeredAnimation);
// animSprite.AnimationTimeScale = _timeout;
//}
//_fallTriggered = true;
}
public override void ActorLeft(ActorComponent actor)
{
base.ActorLeft(actor);
_actorOn = false;
_actor = null;
Holder.Physics.AngularVelocity = 0;
}
public virtual void ProcessTick(Move move, float elapsed)
{
if (_actorOn)
{
if (_actor.Position.X < Holder.Position.X)
{
//actor on left
Holder.Rotation -= 10;
}
else
{
//actor on right
Holder.Rotation += 10;
}
}
else
{
//return to normal position
if (Holder.Rotation < -1 && Holder.Rotation > 180)
{
Holder.Rotation += 5;
}
else if (Holder.Rotation > 1 && Holder.Rotation < 180)
{
Holder.Rotation -= 5;
}
}
}
public virtual void InterpolateTick(float k) { }
public override void CopyTo(TorqueComponent obj)
{
base.CopyTo(obj);
TiltPlatformBehavior obj2 = obj as TiltPlatformBehavior;
obj2.MaxTilt = MaxTilt;
obj2.Tilt = Tilt;
}The object is meant to tilt when the actor lands on it. I'm hoping there is a work around to this problem.
Thanks the help guys.
About the author
Torque Owner Vishal Bhanderi
EDIT: ok it still shivers when the platform is at an angle. It seems like there is nothing in the actor class the handles rotation. So when the player stands on the platform and it starts rotating, the player position is not updated, so it tries to move through the platform. Both problems might be link. Any ideas ?
Does the ground normals for the platform's update anywhere ? I don't see it in the platform's class.
EDIT:
I've figured out that we the player shakes, the _onGround variable is constantly (viewed from puppet) changing from on ground to off ground causing him to change direction rapidly.
EDIT: I found out that the player keeps dropping onto the platform at a steep angle, which is why it keeps switching between the on ground and not. If anyone is making a steep platform, you may need to consider using another state 'sliping' or something.