#smthin does not happen

1 messages · Page 1 of 1 (latest)

half ridge
grave sandal
#

thx

#

btw nice name for the thread

half ridge
#

So where do you want to call the function?

grave sandal
#

when i exit the platform (the white thing (im the blue block))

#

and i use : void OnCollisionExit2D(Collision2D coll)

half ridge
#
  1. mixing canvas ui with physics(colliders) is a very bad idea.
#

Remake your scene with sprite renderers or avoid using collisions.

grave sandal
#

ok so i just delete the component box collider on everithin and replace with sprite render?

half ridge
#

Not box collider. Remove rect transforms(replace with regular transforms), remove Image components and add Sprite renderer. Box colliders are fine on sprite renderers.

grave sandal
#

ok

half ridge
#

It's easier to just scrap that whole canvas and create everything from scratch

grave sandal
#

oh yeah

#

do i create an new canvas or not?

#

i mean if i do need one

half ridge
#

If you do need one, sure.

#

Keep this one or create a new one

grave sandal
#

btw what scale is for 1920 and 1080 (x and y)

#

ok somehow did it

#

and i cant see the player cuz the platform is overlaying him

half ridge
#

Play with the sorting order

grave sandal
#

the platform shall be sorting layer 1 or 2

half ridge
#

try it out and see which one works

grave sandal
#

btw can i do it throught z? cuz it works best

half ridge
#

No. That's gonna mess stuff up. In 2d you should strictly use sorting order

#

and make sure everything has the same Z pos.

grave sandal
#

oh ok

#

now i cant see the player

#

even without the platform

half ridge
#

Why is it parented to the canvas?

grave sandal
#

ooh

half ridge
grave sandal
#

i made the player platform and enemy with sprite render transform and box collider 2D

#

but when i click play i just zooooooom to the blue space

#

next to the platform

half ridge
#

Pause your game during play. Switch to scene view and 3d mode and look around. Where are your objects/camera positioned relative to each other?

grave sandal
#

all objects (dont count main cam) have z 0 if u mean that

#

and cam is z -10

half ridge
#

Take a screenshot of the scene so that all the objects and camera gizmos are visible.

grave sandal
half ridge
#

Seems to be fine according to the camera preview

grave sandal
#

i guess so

#

but still neds to ifx it

half ridge
#

fix what?

#

I don't understand the issue

grave sandal
#

here

#

i litteraly start the game and this happens

half ridge
#

What happens? I don't understand what the problem is from that video.

grave sandal
#

the cube just go away from the platform

#

and i want to make the cube be on the platform and detect when i left the platform

half ridge
#

Share screenshots of player and platform inspectors

grave sandal
#

ok

half ridge
#

At least one of the colliding objects needs a rigidbody for physics events to get fired.

grave sandal
#

the player have rigid body

#

in my perspective of the screenshot it was there

#

but still how do i fix

#

heeey

half ridge
#

It could also be because the objects start as already colliding, so on exit is not called.

grave sandal
#

yeah but the problem is the player just go up

#

without me wanting it

half ridge
#

Share your code again

grave sandal
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovment : MonoBehaviour
{
    private Input input;
    private Rigidbody2D rb;
    public Vector2 input_Movment;
    public float moveSpeed = 10f;


    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        input = new Input();
        



        InputEnable();
    }

    private void InputEnable()
    {
        input.Enable();
    }
    private void InputDisable()
    {
        input.Disable();
    }
    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.name == "Enemy")
        {
            Debug.Log("coll");
            return;
        }
        
    }
    void OnCollisionExit2D(Collision2D coll)
    {
        
        if (coll.gameObject.name == "Platform")
        {
            Debug.Log("haha U gay");
            return;
        }
    }

    private void FixedUpdate()
    {
        Vector2 moveInput = input.Character.Move.ReadValue<Vector2>();
        rb.velocity = moveInput * moveSpeed;
    }
}
#

its bcz the platform have box colider cuz without it it works normaly but i cant detect the collisions without collider

half ridge
#

Comment out input.Disable();

grave sandal
#

why?

#
  1. it never gets called
#
  1. its for input
half ridge
#

Because that's the only reason I can think of why your character floats up without you doing anything

grave sandal
#

cant it be cuz im in the block that have box collider so the block makes me go out of him?

#

bcz without box collider on the platform it works fine

half ridge
grave sandal
#

it teleported

#

so how can i fix it?

half ridge
#

If you want to disable physical collisions between the platform and the character, mark it as a trigger.

grave sandal
#

but will it detect the exit?

#

what does trigger even mean

half ridge
#

Did you change it to OnTriggerExit?

grave sandal
#

ooh

half ridge
#

It means that the objects don't collide physically.

#

Only trigger events are invoked

grave sandal
#

what shall i change collider2D to?

#

void OnTriggerExit2D(Collider2D coll)

#

cuz i tried Trigger2D but error

half ridge
#

look it up in the docs

grave sandal
#

thx