I have 2 objects one is a player object and the other is an invisible box Colider parented to the camera. now when the player comes too close to the plane the camera moves up at the same speed as the player which works great with a player that moves like the spaceship in R-Type with a fixed movement speed but i now need to apply this to a character that moves more like mario so when the the player jumps the camera is very jumpy because its moving faster than the player most of the time.
this is the code that i wrote for the original purposes
var LeftPane : Transform;
var LeftPaneContactSpeed = 5;
var RightPane : Transform;
var RightPaneContactSpeed = 60;
var TopPane : Transform;
var TopPaneContactSpeed = 120;
var BottomPane : Transform;
var BottomPaneContactSpeed = 120;
var Player : Transform;
var Constant = true;
var ConstantSpeed = 15;
public var DistanceLeft : float;
public var DistanceRight : float;
public var DistanceTop : float;
public var DistanceBottom : float;
public var MinimalDistanceLeft : float;
public var MinimalDistanceRight : float;
public var MinimalDistanceTop : float;
public var MinimalDistanceBottom : float;
function Update ()
{
DistanceRight = Player.renderer.bounds.min.x - RightPane.position.x;
DistanceLeft = Player.renderer.bounds.min.x - LeftPane.position.x;
DistanceTop = Player.renderer.bounds.min.y - TopPane.position.y;
DistanceBottom = Player.renderer.bounds.min.y - BottomPane.position.y;
if (DistanceRight < MinimalDistanceRight)
{
transform.Translate(RightPaneContactSpeed*Time.deltaTime, 0, 0);
}
else
{
if (DistanceLeft > MinimalDistanceLeft)
{
transform.Translate(LeftPaneContactSpeed*Time.deltaTime, 0, 0);
}
else
{
if (Constant == true)
{
transform.Translate(ConstantSpeed*Time.deltaTime, 0, 0);
}
}
}
if (DistanceTop > MinimalDistanceTop)
{
transform.Translate(0, TopPaneContactSpeed*Time.deltaTime, 0);
}
else
{
if (DistanceBottom < MinimalDistanceBottom)
{
transform.Translate(0, -BottomPaneContactSpeed*Time.deltaTime, 0);
}
}
}
what i need to do is track the upward movement velocity of the player and setting that value to
var TopPaneContactSpeed = 120;
but i’m clueless as to how to obtain the upwards velocity of the player.
can anybody help me here?