I am creating a platformer like game and have been set the task to create my own script for movement and collisions rather than using the normal method of adding force to a rigid body and all my attempts haven’t worked.
Subject is the gameobject I will be moving, Limits is the collider assigned to the gameobject.
This is my latest attempt but this one doesn’t work either, please help.
public void moveSubject(float Tx, float Ty, float Tz )
{
Tx *= MaxMoveSpeed;
Ty *= MaxMoveSpeed;
RaycastHit hit;
if ((Physics.Raycast(Subject.transform.position,Vector3.right, out hit, (Limits.bounds.extents.x + 0.1f), 10)) && (Tx > 0))
{
Tx = 0;
}
if ((Physics.Raycast(Subject.transform.position, Vector3.left, out hit, (Limits.bounds.extents.x + 0.1f), 10)) && (Tx < 0))
{
Tx = 0;
}
if ((Physics.Raycast(Subject.transform.position, Vector3.up, out hit, (Limits.bounds.extents.y + 0.1f), 10)) && (Ty > 0))
{
Ty = 0;
}
if ((Physics.Raycast(Subject.transform.position, Vector3.down, out hit, (Limits.bounds.extents.y + 0.1f), 10)) && (Ty < 0))
{
Ty = 0;
}
TVector = new Vector3(Tx, Ty, Tz);
Subject.transform.Translate(TVector);
}