Smikkelbakje
Smikkelbakje
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
im having a lot of trouble trying to combine them the player shouldnt be able to move in the air its a jump king style script
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
it works but it doesnt have the jump charge things im gonna try to implement that in your script and see how it works
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
i will be back in ~1 hour
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
ok thanks!
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
im trying to figure out why but cant
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
the jump has became very inconsistand and it doesnt move left or right anymore
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
yea
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Smoovement : MonoBehaviour
{
public float walkSpeed;
public float moveInput;
public bool isGrounded;
private Rigidbody2D rb;
public LayerMask groundmask;
public float jumplength;
public PhysicsMaterial2D bounceMat, normalMat;
public bool canJump = true;
public float jumpValue = 0.0f;
public float distance = 0.6f;
public LayerMask wallLayer;
public bool isTouchingWallL = false;
public bool isTouchingWallR = false;

// Start is called before the first frame update
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
moveInput = Input.GetAxisRaw("Horizontal");

if(jumpValue == 0.0f && isGrounded)
{
rb.AddForce(new Vector2(moveInput * walkSpeed, 0), ForceMode2D.Impulse);
}

isGrounded = Physics2D.OverlapBox(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f),
new Vector2(0.9f, 0.4f), 0f, groundmask);

isTouchingWallR = Physics2D.Raycast(transform.position, Vector2.right, distance, wallLayer);
isTouchingWallL = Physics2D.Raycast(transform.position, Vector2.left, distance, wallLayer);

if(jumpValue >= 0 && !isGrounded && (isTouchingWallL || isTouchingWallR))
{
rb.sharedMaterial = bounceMat;
}
else
{
rb.sharedMaterial = normalMat;
}

if(Input.GetKey("space") && isGrounded && canJump)
{
jumpValue += 2.3f;

}

if(Input.GetKeyDown("space") && isGrounded && canJump)
{
rb.AddForce(new Vector2(0, 0), ForceMode2D.Impulse);

}

if(jumpValue >= jumplength && isGrounded)
{
float tempx = moveInput * walkSpeed;
float tempy = jumpValue;
rb.AddForce(new Vector2(tempx, tempy), ForceMode2D.Impulse);
Invoke("ResetJump", 0.3f);
}

if(Input.GetKeyUp("space")){
if(isGrounded){
rb.AddForce(new Vector2(moveInput * walkSpeed, jumpValue), ForceMode2D.Impulse);
jumpValue = 0.0f;
}
canJump = true;
}

if(jumpValue == 0){
canJump = true;
}
}

void ResetJump()
{
canJump = false;
jumpValue = 0;
}

void OndrawnGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawCube(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f), new Vector2(0.9f, 0.2f));
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Smoovement : MonoBehaviour
{
public float walkSpeed;
public float moveInput;
public bool isGrounded;
private Rigidbody2D rb;
public LayerMask groundmask;
public float jumplength;
public PhysicsMaterial2D bounceMat, normalMat;
public bool canJump = true;
public float jumpValue = 0.0f;
public float distance = 0.6f;
public LayerMask wallLayer;
public bool isTouchingWallL = false;
public bool isTouchingWallR = false;

// Start is called before the first frame update
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
moveInput = Input.GetAxisRaw("Horizontal");

if(jumpValue == 0.0f && isGrounded)
{
rb.AddForce(new Vector2(moveInput * walkSpeed, 0), ForceMode2D.Impulse);
}

isGrounded = Physics2D.OverlapBox(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f),
new Vector2(0.9f, 0.4f), 0f, groundmask);

isTouchingWallR = Physics2D.Raycast(transform.position, Vector2.right, distance, wallLayer);
isTouchingWallL = Physics2D.Raycast(transform.position, Vector2.left, distance, wallLayer);

if(jumpValue >= 0 && !isGrounded && (isTouchingWallL || isTouchingWallR))
{
rb.sharedMaterial = bounceMat;
}
else
{
rb.sharedMaterial = normalMat;
}

if(Input.GetKey("space") && isGrounded && canJump)
{
jumpValue += 2.3f;

}

if(Input.GetKeyDown("space") && isGrounded && canJump)
{
rb.AddForce(new Vector2(0, 0), ForceMode2D.Impulse);

}

if(jumpValue >= jumplength && isGrounded)
{
float tempx = moveInput * walkSpeed;
float tempy = jumpValue;
rb.AddForce(new Vector2(tempx, tempy), ForceMode2D.Impulse);
Invoke("ResetJump", 0.3f);
}

if(Input.GetKeyUp("space")){
if(isGrounded){
rb.AddForce(new Vector2(moveInput * walkSpeed, jumpValue), ForceMode2D.Impulse);
jumpValue = 0.0f;
}
canJump = true;
}

if(jumpValue == 0){
canJump = true;
}
}

void ResetJump()
{
canJump = false;
jumpValue = 0;
}

void OndrawnGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawCube(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f), new Vector2(0.9f, 0.2f));
}
}
changed them all to rb.AddForce the player is now on iceskates
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
if i replace rb.velocity = new Vector2(moveInput * walkSpeed, jumpValue); with rb.AddForce(rb.transform.up * jumpValue); it still does the same thing
27 replies
CC#
Created by Smikkelbakje on 1/4/2023 in #help
❔ slide bug in csharp script in unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Smoovement : MonoBehaviour
{
public float walkSpeed;
public float moveInput;
public bool isGrounded;
private Rigidbody2D rb;
public LayerMask groundmask;
public float jumplength;
public PhysicsMaterial2D bounceMat, normalMat;
public bool canJump = true;
public float jumpValue = 0.0f;
public float distance = 0.6f;
public LayerMask wallLayer;
public bool isTouchingWallL = false;
public bool isTouchingWallR = false;

// Start is called before the first frame update
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
moveInput = Input.GetAxisRaw("Horizontal");

if(jumpValue == 0.0f && isGrounded)
{
rb.velocity = new Vector2(moveInput * walkSpeed, rb.velocity.y);
}

isGrounded = Physics2D.OverlapBox(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f),
new Vector2(0.9f, 0.4f), 0f, groundmask);

isTouchingWallR = Physics2D.Raycast(transform.position, Vector2.right, distance, wallLayer);
isTouchingWallL = Physics2D.Raycast(transform.position, Vector2.left, distance, wallLayer);

if(jumpValue >= 0 && !isGrounded && (isTouchingWallL || isTouchingWallR))
{
rb.sharedMaterial = bounceMat;
}
else
{
rb.sharedMaterial = normalMat;
}

if(Input.GetKey("space") && isGrounded && canJump)
{
jumpValue += 0.3f;

}

if(Input.GetKeyDown("space") && isGrounded && canJump)
{
rb.velocity = new Vector2(0.0f, rb.velocity.y);

}

if(jumpValue >= jumplength && isGrounded)
{
float tempx = moveInput * walkSpeed;
float tempy = jumpValue;
rb.velocity = new Vector2(tempx, tempy);
Invoke("ResetJump", 0.3f);
}

if(Input.GetKeyUp("space")){
if(isGrounded){
rb.velocity = new Vector2(moveInput * walkSpeed, jumpValue);
jumpValue = 0.0f;
}
canJump = true;
}

if(jumpValue == 0){
canJump = true;
}
}

void ResetJump()
{
canJump = false;
jumpValue = 0;
}

void OndrawnGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawCube(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f), new Vector2(0.9f, 0.2f));
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Smoovement : MonoBehaviour
{
public float walkSpeed;
public float moveInput;
public bool isGrounded;
private Rigidbody2D rb;
public LayerMask groundmask;
public float jumplength;
public PhysicsMaterial2D bounceMat, normalMat;
public bool canJump = true;
public float jumpValue = 0.0f;
public float distance = 0.6f;
public LayerMask wallLayer;
public bool isTouchingWallL = false;
public bool isTouchingWallR = false;

// Start is called before the first frame update
void Start()
{
rb = gameObject.GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
moveInput = Input.GetAxisRaw("Horizontal");

if(jumpValue == 0.0f && isGrounded)
{
rb.velocity = new Vector2(moveInput * walkSpeed, rb.velocity.y);
}

isGrounded = Physics2D.OverlapBox(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f),
new Vector2(0.9f, 0.4f), 0f, groundmask);

isTouchingWallR = Physics2D.Raycast(transform.position, Vector2.right, distance, wallLayer);
isTouchingWallL = Physics2D.Raycast(transform.position, Vector2.left, distance, wallLayer);

if(jumpValue >= 0 && !isGrounded && (isTouchingWallL || isTouchingWallR))
{
rb.sharedMaterial = bounceMat;
}
else
{
rb.sharedMaterial = normalMat;
}

if(Input.GetKey("space") && isGrounded && canJump)
{
jumpValue += 0.3f;

}

if(Input.GetKeyDown("space") && isGrounded && canJump)
{
rb.velocity = new Vector2(0.0f, rb.velocity.y);

}

if(jumpValue >= jumplength && isGrounded)
{
float tempx = moveInput * walkSpeed;
float tempy = jumpValue;
rb.velocity = new Vector2(tempx, tempy);
Invoke("ResetJump", 0.3f);
}

if(Input.GetKeyUp("space")){
if(isGrounded){
rb.velocity = new Vector2(moveInput * walkSpeed, jumpValue);
jumpValue = 0.0f;
}
canJump = true;
}

if(jumpValue == 0){
canJump = true;
}
}

void ResetJump()
{
canJump = false;
jumpValue = 0;
}

void OndrawnGizmosSelected()
{
Gizmos.color = Color.green;
Gizmos.DrawCube(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y - 0.5f), new Vector2(0.9f, 0.2f));
}
}
i tried cleaning it up i have no idea how to fix this i have sat here a couple of hours trying to find solutions
27 replies