r/Unity3D – Telegram
r/Unity3D
266 subscribers
12.7K photos
15.6K videos
14 files
48K links
News about the Unity engine and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).
Download Telegram
Platformer walljumping when I don't want it to

So I'm kinda new at this and trying to make a simple platformer noscript and I've gotten pretty close to what I want. Issue here is that when the character touches a wall instead of falling it just levitates midair, which allows for it to basically save from every fall by walljumping. Help?

{
//Movement
public float speed;
public float jump;
float moveVelocity;
public Rigidbody2D rb;
bool isGrounded;

void Update()
{
//Grounded?
if (isGrounded == true)
{
//jumping
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.W))
{

GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
}

}

moveVelocity = 0;

//Left Right Movement
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
{
moveVelocity = -speed;
}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
{
moveVelocity = speed;
}

GetComponent<Rigidbody2D>().velocity = new Vector2(moveVelocity, GetComponent<Rigidbody2D>().velocity.y);

}
void OnCollisionEnter2D(Collision2D col)
{
Debug.Log("OnCollisionEnter2D");
isGrounded = true;
}
void OnCollisionExit2D(Collision2D col)
{
Debug.Log("OnCollisionExit2D");
isGrounded = false;
}
}

https://redd.it/1gz7vsi
@r_Unity3D
Pipe system

So,, my character is liquid and i was thinking to add a pipe system that the character can go inn and go to different parts of the map, i just don't know how to do it, any ideas?

https://redd.it/1gz5my2
@r_Unity3D
How can I make a background?

Hi, i'm a beginner on Unity and I'm sure how to make a background/map. I've seen a few tutorial about doing a tilemap, but everytime i do this, the tilemap overlap my character, so i'm not sure where i can look to make the character overlap the tilemap/background?
Btw srry for my bad english, its not my first language😅
Thx.

https://redd.it/1gz15pz
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
I put a great big Akira inspired freight elevator in my game about a quantum cat. It really helps sell the scale of the environments.

https://redd.it/1gzdnl2
@r_Unity3D
What open source projects have you been a part of? Is it still active?

Hello everybody

I've been wanting to contribute to open source projects to sharpen my skills, but haven't found anything yet. wanted to see if you guys have been a part of the game dev open source community.
would love to hear about your experience

https://redd.it/1gzi2pf
@r_Unity3D
Media is too big
VIEW IN TELEGRAM
Made a fire stream out of symbols. Does it look good? Current battle gameplay: everything shoots automatically. You just reload, maybe craft something mid-fight (like a shield or a support drone) and escape in time. Still deciding if I should rework it to give the player more control...

https://redd.it/1gzkvwt
@r_Unity3D
2D Platform Game for School Project... NEED HELP

Hey guys, this is my code in C# that i actually got from chatGPT because im not really good in coding haha... The problem is that for player2 (frog) it is not actally reseting horizontal velocity only after landing but its like allways... and if there is no reseting of horizontal velocity the frog is sliding after landing.. Can anybody help me with that somehow?

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

public class TwoPlayerMovement : MonoBehaviour
{
    Header("Player 1 Settings")
    public Rigidbody2D rb1;
    public Transform groundCheck1;
    public LayerMask groundLayer1;
    private float horizontal1;
    private float speed1 = 8f;
    private float jumpingPower1 = 16f;
    private bool isFacingRight1 = true;

    Header("Player 2 Settings (Frog)")
    public Rigidbody2D rb2;
    public Transform groundCheck2;
    public LayerMask groundLayer2;
    private bool isGrounded2;
    private bool isChargingJump2 = false;
    private bool wasInAir2 = false; // Detects if the frog was previously in the air
    private float chargeTime2 = 0f;
    private float maxChargeTime2 = 1.5f; // Maximum charge time
    private float minJumpPower2 = 6f; // Minimum jump strength
    private float maxJumpPower2 = 16f; // Maximum jump strength
    private float jumpDirection2 = 0f; // Direction of the jump (-1 = left, 1 = right)
    private bool isFacingRight2 = true;

    private void Update()
    {
        // Player 1 Controls
        horizontal1 = Input.GetAxisRaw("HorizontalP1"); // Custom axis for Player 1
        if (Input.GetButtonDown("JumpP1") && IsGrounded(groundCheck1, groundLayer1))
        {
            rb1.velocity = new Vector2(rb1.velocity.x, jumpingPower1);
        }
        if (Input.GetButtonUp("JumpP1") && rb1.velocity.y > 0f)
        {
            rb1.velocity = new Vector2(rb1.velocity.x, rb1.velocity.y 0.5f);
        }

        Flip(ref isFacingRight1, horizontal1, rb1.transform);

        // Player 2 (Frog) Controls
        isGrounded2 = IsGrounded(groundCheck2, groundLayer2);

        if (isGrounded2)
        {
            // If frog just landed, reset horizontal velocity
            if (wasInAir2)
            {
                rb2.velocity = new Vector2(0f, rb2.velocity.y); // Reset horizontal velocity only after landing
                wasInAir2 = false;
            }

            // Start charging the jump
            if (Input.GetButtonDown("JumpP2"))
            {
                isChargingJump2 = true;
                chargeTime2 = 0f;
            }

            // Set jump direction based on input
            float inputHorizontal = Input.GetAxisRaw("HorizontalP2");
            if (inputHorizontal != 0)
            {
                jumpDirection2 = inputHorizontal > 0 ? 1f : -1f;
                isFacingRight2 = jumpDirection2 > 0;
                Flip(ref isFacingRight2, jumpDirection2, rb2.transform);
            }
        }

        // Charge the jump
        if (isChargingJump2)
        {
            chargeTime2 += Time.deltaTime;
            chargeTime2 = Mathf.Clamp(chargeTime2, 0f, maxChargeTime2); // Limit to max charge time
        }

        // Release the jump
        if (Input.GetButtonUp("JumpP2") && isChargingJump2)
        {
            isChargingJump2 = false;

            // Calculate jump power based on charge time
            float jumpPower = Mathf.Lerp(minJumpPower2, maxJumpPower2, chargeTime2 / maxChargeTime2);

            // Apply the jump
            rb2.velocity = new Vector2(jumpDirection2
jumpPower, jumpPower);

            // Mark that the frog is in the air
            wasInAir2 = true;
        }
    }
    private void FixedUpdate()
    {
        // Apply horizontal movement for Player 1 only
        rb1.velocity = new Vector2(horizontal1 speed1, rb1.velocity.y);

        // The frog retains its horizontal velocity when grounded
        if (!isGrounded2 && !wasInAir2)
        {
            // Keep horizontal velocity in the air until the jump is released
            rb2.velocity = new Vector2(rb2.velocity.x, rb2.velocity.y);
        }
    }

    private bool IsGrounded(Transform groundCheck, LayerMask groundLayer)
    {
        // Check if the player is on the ground (groundLayer)
        return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
    }

    private void Flip(ref bool isFacingRight, float horizontal, Transform playerTransform)
    {
        if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
        {
            isFacingRight = !isFacingRight;
            Vector3 localScale = playerTransform.localScale;
            localScale.x
= -1f;
            playerTransform.localScale = localScale;
        }
    }

    private void OnDrawGizmos()
    {
        // Draw the ground check areas for debugging
        if (groundCheck1 != null)
        {
            Gizmos.color = Color.green;
            Gizmos.DrawWireSphere(groundCheck1.position, 0.2f);
        }
        if (groundCheck2 != null)
        {
            Gizmos.color = Color.blue;
            Gizmos.DrawWireSphere(groundCheck2.position, 0.2f);
        }
    }
}

https://redd.it/1gzm1by
@r_Unity3D
Click on shapes and do some letter combination... the game. I made it. Go play it

Don't be a SQUARE is fucking out now. Click on the shapes or whatever and do some letter combination shit. You won't win cause its kinda hard. I didn't finish it. Go play it!

https://differentpixels.itch.io/dont-be-a-square

https://redd.it/1gzqmjk
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
A Little Animation Explaining how Meshes are Rendered for a Video I'm Working on

https://redd.it/1gzml6q
@r_Unity3D