–1 vote

Hi, can someone convert this script to gdscript? Thank you in advance!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
[SerializeField]
LayerMask lmWalls;
[SerializeField]
float fJumpVelocity = 5;

Rigidbody2D rigid;

float fJumpPressedRemember = 0;
[SerializeField]
float fJumpPressedRememberTime = 0.2f;

float fGroundedRemember = 0;
[SerializeField]
float fGroundedRememberTime = 0.25f;

[SerializeField]
float fHorizontalAcceleration = 1;
[SerializeField]
[Range(0, 1)]
float fHorizontalDampingBasic = 0.5f;
[SerializeField]
[Range(0, 1)]
float fHorizontalDampingWhenStopping = 0.5f;
[SerializeField]
[Range(0, 1)]
float fHorizontalDampingWhenTurning = 0.5f;

[SerializeField]
[Range(0, 1)]
float fCutJumpHeight = 0.5f;

void Start ()
{
    rigid = GetComponent<Rigidbody2D>();
}

void Update ()
{
    Vector2 v2GroundedBoxCheckPosition = (Vector2)transform.position + new Vector2(0, -0.01f);
    Vector2 v2GroundedBoxCheckScale = (Vector2)transform.localScale + new Vector2(-0.02f, 0);
    bool bGrounded = Physics2D.OverlapBox(v2GroundedBoxCheckPosition, v2GroundedBoxCheckScale, 0, lmWalls);

    fGroundedRemember -= Time.deltaTime;
    if (bGrounded)
    {
        fGroundedRemember = fGroundedRememberTime;
    }

    fJumpPressedRemember -= Time.deltaTime;
    if (Input.GetButtonDown("Jump"))
    {
        fJumpPressedRemember = fJumpPressedRememberTime;
    }

    if (Input.GetButtonUp("Jump"))
    {
        if (rigid.velocity.y > 0)
        {
            rigid.velocity = new Vector2(rigid.velocity.x, rigid.velocity.y * fCutJumpHeight);
        }
    }

    if ((fJumpPressedRemember > 0) && (fGroundedRemember > 0))
    {
        fJumpPressedRemember = 0;
        fGroundedRemember = 0;
        rigid.velocity = new Vector2(rigid.velocity.x, fJumpVelocity);
    }

    float fHorizontalVelocity = rigid.velocity.x;
    fHorizontalVelocity += Input.GetAxisRaw("Horizontal");

    if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) < 0.01f)
        fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingWhenStopping, Time.deltaTime * 10f);
    else if (Mathf.Sign(Input.GetAxisRaw("Horizontal")) != Mathf.Sign(fHorizontalVelocity))
        fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingWhenTurning, Time.deltaTime * 10f);
    else
        fHorizontalVelocity *= Mathf.Pow(1f - fHorizontalDampingBasic, Time.deltaTime * 10f);

    rigid.velocity = new Vector2(fHorizontalVelocity, rigid.velocity.y);
}
}
in Engine by (21 points)

Have you ever considered learning gdscript?
I'd love to ask unity answers to convert gdscript, and count how many seconds it takes for the account to get banned.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.