Guys below is my Code for My PlaycontrollerScript and PlatformMover script what i am trying to achieve here is i want when my player jump on the platform that particular group of platform to go down ,basically like doodle jump ,but as i am doing something wrong here platform groups are spawning perfectly but its not moving ,i am pretty new to things. can someone give me an idea of what i am doing wrong or guide me to a tutorial or something any help will be appreciated
<pre>public class PlatformMover : MonoBehaviour {
public GameObject[] easyGroups;
public GameObject currentGroup;
public GameObject nextGroup;
public GameObject startingPlatform;
public GameObject lastObjectJumped;
public int rand;
public int easyMin;
public int easyMax;
public Transform startingGroupTran;
public Transform topSpawnTran;
public Transform lowestTran;
public float speedDown;
public float toLerpDif;
public Vector3 toLerp;
void OnEnable ()
{
FirstGroupFunction();
}
void Update()
{
if (nextGroup.transform.position.y <= 0)
{
newGroup();
}
groupMoveFunction();
}
void FirstGroupFunction()
{
rand = Random.Range(easyMin, easyMax);
currentGroup = Instantiate(easyGroups[rand], startingGroupTran.position, startingGroupTran.rotation) as GameObject;
rand = Random.Range(easyMin, easyMax);
nextGroup = Instantiate(easyGroups[rand], topSpawnTran.position, topSpawnTran.rotation) as GameObject;
nextGroup.transform.SetParent(currentGroup.transform);
startingPlatform.transform.SetParent(currentGroup.transform);
}
void groupMoveFunction()
{
currentGroup.transform.position = Vector3.Lerp(currentGroup.transform.position, toLerp, speedDown * Time.deltaTime);
}
void newGroup()
{
nextGroup.transform.SetParent(null);
Destroy(currentGroup);
currentGroup = nextGroup;
rand = Random.Range(easyMin, easyMax);
nextGroup = Instantiate(easyGroups[rand], topSpawnTran.position, topSpawnTran.rotation) as GameObject;
nextGroup.transform.SetParent(currentGroup.transform);
toLerpDif = lastObjectJumped.transform.position.y - lowestTran.position.y;
toLerp = new Vector3(0, currentGroup.transform.position.y - toLerpDif, 0);
}
<pre>public class Pandacontroller : MonoBehaviour {
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public float jumpForce = 700f;
public LayerMask whatisGround;
public PlatformMover controller;
public string lastjump;
public GameObject panda;
public Rigidbody2D pandaRigid;
public bool isJumping;
public int jumptop;
public Vector3 toLerp;
void OnTriggerEnter2d(Collider2D other)
{
if (other.tag == "Platforms")
{
isJumping = true;
pandaRigid.gravityScale = 0;
pandaRigid.velocity = Vector3.zero;
}
if(other.tag == "Platforms")
{
lastjump = "Platforms";
controller.lastObjectJumped = other.gameObject;
controller.toLerpDif = controller.lastObjectJumped.transform.position.y - controller.lowestTran.position.y;
controller.toLerp = new Vector3(0, controller.currentGroup.transform.position.y - controller.toLerpDif, 0);
}
}
void Start ()
{
anim = GetComponent<Animator>();
}
void FixedUpdate ()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatisGround);
anim.SetBool("Ground", grounded);
anim.SetFloat("vSpeed", GetComponent<Rigidbody2D>().velocity.y);
float move = Input.GetAxisRaw("Horizontal");
GetComponent<Rigidbody2D>().velocity = new Vector2(move * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);
anim.SetFloat("speed", Mathf.Abs(move));
if (move > 0 && !facingRight)
flip();
else if (move < 0 && facingRight)
flip();
}
void Update()
{
if (grounded && Input.GetKeyDown(KeyCode.Space))
{
anim.SetBool("Ground", false);
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, jumpForce));
}
}
void flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
What I have tried:
I have Tried to normal instantiation in a specific point it worked but was not what i was looking for ,i did use random continues generations of platform moving down which worked but its not what i was looking for too but the way they do it in doodle jump seems good enough for me so i want to try that