#Help

1 messages ยท Page 1 of 1 (latest)

lean coral
#

That other channel is a mess to follow right now. Ask your question in here.

misty jackal
#

ok

#

this code is or the plyer

#

in the player collision

lean coral
#

That's not an issue

misty jackal
#

hait

lean coral
#

Don't worry, just continue

misty jackal
#

see

#

i folow Brakys tetoril

#

vedio

#

but i tryed to chang the code by my self

#

the real 1

#

is to make the player movment fuls

#

but i tryed to made the obstacle an bounser

#

shang it to bounser

#

change

lean coral
#

Ok

So you want:

  1. Player to collide with the SSSD game object
  2. Make the player bounce off the object?
misty jackal
#

i thik you mean make the player when it hits the SSSD object
add force to up

lean coral
#

Ah ok. I see.

#

Can you screenshot your player game object in here?

misty jackal
#

yes

lean coral
#

Ok cool.

So what we need to do is change a few things.

First of all your bouncer object is not going to collide with your player because it's too low. So what we can do is adjust the collider to be above the bouncer.

So on the bouncer adjust the "center" so the middle (second value) is 1. That should show you the collider is above the ground.

#

Then we do not actually want the collider to collide with the player (strange I know), but we want a trigger. This will allow the player to go through the object.

misty jackal
#

can u wait a few secounds to read it

lean coral
#

The messages won't disappear ๐Ÿ˜Š take all the time you need.

misty jackal
#

Y or Z or X

lean coral
misty jackal
lean coral
misty jackal
lean coral
#

On your Box Collider component there is a Center option

misty jackal
#

ok

#

i see

lean coral
#

Yes! Excellent.

#

While you're there check the is trigger checkbox

misty jackal
lean coral
#

Ok cool. So now we have to go to your code.

misty jackal
#

why we set the center to 1

lean coral
#

That offsets the collider by +1 on the Y axis in the world. (That means it's now above your cube object)

misty jackal
#

to make the player dond collid with it

lean coral
misty jackal
#

ok

lean coral
#

For your code, we need to adjust the method from OnCollisionEnter to the following:

private void OnTriggerEnter(Collider other)
    {
        // Copy your if statement here 
    }
misty jackal
#

me in the cod

#

e

lean coral
#

So earlier you showed your player script had a method in it, we need to adjust that

misty jackal
#

i should code the if by my self
yes?

#

should

lean coral
#

Yes, you can copy the if you were using.

misty jackal
#

no

#

i dont copy hhh

lean coral
#

Haha. That's fine we can go through it.

misty jackal
#

iam tiping

#

y

lean coral
#

We'll do it slightly differently to how you originally did it, as we would rather use tags (or layers).

if(other.gameObject.CompareTag("bouncer"))
{
    RB.AddForce(0, myBounceForce, 0);
}

Then, you can add a tag to your SSSD object.

misty jackal
#

wait

misty jackal
#

why its not collider

lean coral
#

Because our trigger uses a different object

OnCollisionEnter uses a Collision object

OnTriggerEnter uses a collider

misty jackal
lean coral
#

Excellent. So now we just need to add the tag.

#

And that's the last thing.

misty jackal
#

ok

#

i will add

lean coral
#

Excellent. Now if you play the game it should work.

misty jackal
lean coral
#

Any issues with it just post them here.

misty jackal
#

should i change any thing here

lean coral
#

Nope

misty jackal
#

it didnt workd

lean coral
#

Can you explain a little more?

#

On your screenshot you character isn't on the bouncer

misty jackal
#

see

lean coral
#

Ok so first of all let's make sure that the trigger event is firing.

Let's add Debug.Log("trigger") to our OnTriggerEnter method.

#

Then let's run it again.

#

Do not put it inside the if statement

misty jackal
lean coral
#

The player script

#

Before the if statement.

misty jackal
#

there is 2 scripts

lean coral
#

PlayerCollision

misty jackal
#

ok

lean coral
#

Excellent

#

Now we'll run it again

#

We just want to see if the method gets called

misty jackal
#

it didnt

lean coral
#

Ok, if you go to SSSD to the Box Collider there should be an edit collider button

#

Just make sure that's above ground.

misty jackal
lean coral
#

Ok yes.

Then we'll go to our player object and make sure that our PlayerCollision component is correct

misty jackal
#

is tregger

#

i

lean coral
#

Can you expand both Player Collision and Rigidbody

#

Player shouldn't be a trigger

misty jackal
lean coral
#

Can I see Player Collision as well

misty jackal
lean coral
#

Ok, something isn't right here

You may need to restart unity.

Your code isn't reflective of what is on Unity.

Your Bouns Force should be My Bounce Force

misty jackal
#

oh
yes

#

how its

lean coral
#

Did you save the file?

#

Make sure you save to trigger a reload!

misty jackal
#

\iam mad

#

iam sorry

lean coral
#

Happens to everyone

#

Ok hopefully it will now work

#

๐Ÿ˜Š

misty jackal
#

thw debug.log worked

lean coral
#

You need to set the Rigidbody inside your PlayerCollision component.

#

It's showing as empty

misty jackal
#

my hero

#

it works

lean coral
#

No problem.

misty jackal
#

thanks so much