Player Movement Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PM : MonoBehaviour
{
private float horizontal;
private float jumpingPower = 24f;
private bool isFacingRight = true;
private bool IsShimmered;
private bool ShimmerSpam;
private Vector3 respawnPoint;
public GameObject FallDetector;
public static Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundLayer;
[SerializeField] private TrailRenderer tr;
[SerializeField] private float speed = 7f;
private void Start()
{
respawnPoint = transform.position;
}
private void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");
if (Input.GetButtonDown("Jump") && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
Flip();
}
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
}
//HERE IS WHERE THE SUPPOSED ERROR IS
private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}
private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
Vector3 localScale = transform.localScale;
isFacingRight = !isFacingRight;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "FallDetector")
{
transform.position = respawnPoint;
}
if(collision.tag == "CheckPoint")
{
respawnPoint = transform.position;
}
}
}
The script that enables low gravity zones:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shimmeur : MonoBehaviour
{
private GameObject player;
public PM script;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
PM.rb.gravityScale = 0.5f;
}
else
{
PM.rb.gravityScale = 3f;
}
}
}
I do know that this question has already been posted several times but after searching for a while i never found the answer i need,any ideas?