- Home /
Question by
gizelgeng · Aug 15, 2020 at 06:00 AM ·
jumprotatingstickingperpendicular
how to jump Perpendicular to the rotating platform
Hello , first of all i wanted to apologize for my bad English. i have a simple jumping game . in this game there are rotating platforms , and a game object , whenever the player clicks mouse the game object should jump and stick to the next platform and rotate with it ,until the player clicks again. i want the game object to jump Perpendicular to the rotating platform` (again sorry for my bad English) but now in my code it dose not. and if i use Vector3.up the game object will fall down ,i've tried every thing but it dose not work
i want the game object to jump in the direction of green arrow and stick to the next platform
, here is my code
Rigidbody2D Rig;
public float Force =500;
public bool gamejump = true;
public Transform platformParent;
bool playerforce = false;
bool setpos = false;
Vector2 pos = new Vector2(0, 0);
public Collider2D Ccollider;
public bool bottom =false;
public bool SPressed = false;
void Start()
{
Rig = GetComponent<Rigidbody2D>();
Ccollider = GetComponent<CircleCollider2D>();
}
void Update()
{
if (SPressed == true && Input.GetKeyDown(KeyCode.Space))
{
print("true");
gamejump = true;
Rig.AddForce(transform.up * Force);
}
if (gamejump == true)
{
transform.SetParent(null);
Rig.isKinematic = false;
setpos = false;
}
else
{
transform.SetParent(platformParent);
Rig.AddForce(new Vector2(0, 0));
Rig.isKinematic = true;
if (setpos == false)
{
setpos = true;
transform.position = pos;
}
/* if(Input.GetMouseButtonDown(0))
{
SPressed = true;
}
if(Input.GetMouseButtonUp(0))
{
SPressed = false;
}
}*/
}
}
void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "Rotate")
{
SPressed = true;
// if(SPressed==true)
//if (Input.GetKey(KeyCode.Space) )
// if (Input.GetMouseButtonDown(0))
// {
// gamejump = true;
/* if (bottom == true)
{
Rig.AddForce(other.transform.up * Force);
}
else
{
Rig.AddForce(other.transform.up * -Force);
}
}
*/
// }
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Rotate")
{
ContactPoint2D contact = collision.contacts[0];
pos = contact.point;
if (collision.contacts.Length>0)
{
bottom = true;
}
else
{
bottom = false;
}
gamejump = false;
}
}
public void OnCollisionExit2D(Collision2D collision)
{
collision.collider.enabled = false;
}
}
i have to press key space 3 times to jump and i don't know why! so that is my main problem for now.
whatsapp-image-2020-08-15-at-102027.jpeg
(22.4 kB)
Comment
Your answer
