#Ground Check

1 messages · Page 1 of 1 (latest)

plush dew
#

Give me a sec

#

is this a 3D game?

glad urchin
#

Yea it's a topdown game I can post a quick image for context if that helps express the nature of things visually

plush dew
#

Code looks like it at least.
Mind posting a screenshot so I get an idea of how it works?

glad urchin
#

Weird, discord is acting a bit buggy, seems like messages aren't updating

#

er sorry the messages just updated now there's some kind of delay

#

here's a quick snapshot of the game, i can delete that if unecessary. temp assets/etc

plush dew
glad urchin
#

I think i need to relog in or something, sec

#

i can also try and take a short vid showing the phasing

#

since that's probably easier than still images or vaguely describing it

#

initially, you can see that with default moveSpeed you don't move through the wall. but as soon as I add like 10 more speed, i can burrow through

#

(getting like a 10-20 second delay here lol)

plush dew
# glad urchin

Screenshot the Rigidbody component properties in the inspector

glad urchin
#

ok its posted, probably going to take about a minute to show up though. messages seem to be registering quicker*

#

I have gravity enabled because i noticed i'll start rotating or drifting when touching things, and gravity kinda forces that down. and I add custom gravity force on top of that to limit vertical jump/double jump

#

I could technically have the script handle gravity as well, but I figure just keeping the native settings might be easier to click off down the line for convenience

#

freezing position fixes the ball roll BUT you phase through walls like your kinematic, so i have to keep that unchecked

#

Ah i'm seeing the problem before seeing the solution (i.e. stopping random locked movement when rotating)- can't jump now because the velocity is canceling out upwards velocity per frame

#

I speculate your right about force being added while rotating which is making the character move without input, but I've gotta figure out how to work jumping into that or any other movement patterns, while removing all ball-like attributes

plush dew
#

Does the wall have a Rigidbody?

glad urchin
#

I tracked the input and there was none so that's gotta be the last remaining cause. the only other thing would be trigger colliders, but afaik those don't produce collisions at all

#

Nope, it sounded expensive and i read you only want that on objects that 'interact' i.e. projectiles/players/enemies/etc

#

i'm keeping things 'performant' (from my limited understanding). Do i need to add a rigid?

#

that'd be a ton of rigid bodies in the scene on top of the projectiles and enemies

plush dew
#

It's not required. It would just have to have been Static instead of Dynamic

glad urchin
#

static as in kinematic correct? Or setting the static check box above

plush dew
#

My bad. I'm thinking Rigidbody2D logic

glad urchin
#

s'all good, it looks like rigid body kinematic isn't working either

plush dew
#

It sounds like you're experiencing a multitude of issues in your current script

#

The approach I would recommend, is to break it all down in to parts, and fix each part individually

#

I wonder if an otherwise blank script with simple movement, would be able to penetrate that wall.

glad urchin
#

i think its speed related

plush dew
glad urchin
#

the standard speed doesn't let me go through which is good. but the more force applied the more you can phase through

#

right, from what i've read it's meant to be static and unmoveable, so it ignores certain things

#

but i think the answer is applying equal opposite force when touching a wall?

#

and or having a raycast that disables sprint when you touch it

#

that way you can never sprint through

plush dew
#

Kinematic is not supposed to be immovable, but moved differently.

glad urchin
#

Ah gotcha

glad urchin
#

if isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore that's the part that i'm seeing

plush dew
#

seeing where?

glad urchin
#

er in terms of how it interacts with the player

plush dew
#

are you using it in the project right now?

glad urchin
#

like if the wall is kinematic, it cannot be moved by another rigid body- but on the flip it doesn't look like its stopping rigid bodies like the player's

#

i use kinematics for the pots

#

like kinematic when sitting in the level, then disable kinematics when thrown

#

then detects ground on collision to shatter, that works perfectly fine

#

i think the random movement might be solved, but i'll have to keep playing to see if it appears again.
But i think setting it to is grounded will fix the getting locked and moving in one direction without input issue seen here: https://gdl.space/aniqinepag.cpp

#

so 1 issue might be solved, the other one is phasing through things which I assumed raycasting might solve? since you're always forward facing when moving

#

like ya hit the wall at a short distance, then it disables your ability to sprint through a boolean as well as turns it off

#

you may be able to sprint while facing sideways then turning forwards, but i think the raycast will be too fast to try and cheeze that

plush dew
#

First, make a simple movement scrip using only AddForce and see if that script alone can phase it through the wall

#

What sort of collider is on the wall?

glad urchin
#

ok

#

just a box collider

plush dew
#

alright

glad urchin
plush dew
#

I may have found the issue

#

You are rotating by transform, not rigidbody

glad urchin
#

I got this script off a video i believe. I think the idea is to override the rigid body rotation because the rotation is disabled to keep it from rolling?

#

like rotating it from the outside, but you could be onto something

plush dew
#

Overriding the Rigidbody rotation would conflict. Not every video out there is made by experts.
It sounds like you just want to freeze an axis of rotation?

glad urchin
#

X and Z because the character is just meant to rotate on one axis

#

Y is the primary axis for left/right rotation

plush dew
#

So why override Rigidbody when it has Freeze Rotation X,Y,Z ?

glad urchin
#

it was rolling in addition to rotating

plush dew
#

huh

glad urchin
#

The script rotates you forward (correct) but treats your character like a ball (makes sense) but that isn't what i want

#

maybe if my character was a ball things would be fine but it isn't

#

it also makes the character fall over or roll when another rigid/collider touches it

plush dew
#

I'm not sure I comprehend

glad urchin
#

er "I want my rigid body to act like a character controller but still have features of a rigid body"

#

"because people say Character controller sucks and is limited, so I'm reprogramming the rigid body so i can have additional features"

#

"because down the line I might want to use some rigid body features that character controller doesn't have"

plush dew
#

brb phone

glad urchin
#

Uh yep, i made a rudimentary movement script and can still pass through walls

#

here's that basic script in action. Just changed the moveSpeed and same issue

#

i think raycasting to stop forward speed might be the best solution here

plush dew
#

(that was a long phone call)

plush dew
glad urchin
#

ye, i just gotta make sure the rays work, the green one is the forward wall detection

#

rays don't cancel eachother out right?

plush dew
#

I don't believe so

glad urchin
#

hmm, i guess my issue now is that the second raycast is firing continually when its not detecting the layermask

plush dew
#

How do you mean?

glad urchin
#

under the void update line is the wall detection ray, it looks like its firing constantly when i hit a wall. but i think whats happenign is an infinite ray is being shot out

#

because its hitting walls in the distance, but doesnt run when im pointing towards the void

#

ah maybe its transform.forward * height is the problem, shooting forward infinitely

#

i was using vector3.forward * height which worked for ground detection, but that kept it in world space and i need to localize it

#

i need something like vector3.forward.local or something like that

plush dew
#

I'm not sure you need that for this.

#

Just set a maxDistance that makes sense

glad urchin
#

ah that's where i messed up, that was missing from my code

#

if(Physics.Raycast(rayCastOffset.position, transform.forward , out hit2, height2, _layerMaskWall))
instead of
if(Physics.Raycast(rayCastOffset.position, transform.forward * height2 , out hit2, _layerMaskWall))

plush dew
#

That works?

glad urchin
#

checking

plush dew
#
//                 origin                  direction           hit info  maxDistance  layermask
if(Physics.Raycast(rayCastOffset.position, transform.forward , out hit2, height2, _layerMaskWall)) 
#

looks good

glad urchin
#

Yea i'm checking, it seems like its not running now but i may still be missing something

// Your code here
     Ray ray2 = new Ray(rayCastOffset.position, transform.forward * height2);
        Physics.Raycast(ray2, out hit2, height2, _layerMaskWall);
        Debug.DrawRay(rayCastOffset.position, transform.forward * height2, Color.green);

        if(Physics.Raycast(rayCastOffset.position, transform.forward , out hit2, height2, _layerMaskWall))
        {

            // disable dashing 
            playerAbilityManager.dashActive = false;
            playerAbilityManager.dashIcon.SetActive(false);

            Debug.Log("Detecting Wall, disabled dashing"); 

        }
#

the ray is def following the transform locally which is good, im just trying to see if the debug log is even firing

#

ok i just tagged my walls as ground thats why

#

the rest i can debug, but do you have time for one last question?

#

I've got this beamer type enemy that shoots rays when it locks onto the character, but i want the wall layermask to break line of sight

#

its another raycast related thing. Do I use two raycasts, or would I use hit.collider.compareTag to differentiate within a single ray? I notice its causing stuttering when i try that

#

it'll interrupt, but the normal beam will stutter and stay in the previous position

plush dew
#

I would just use a Raycast or SphereCast, and if it was null, the weapon can shoot.

glad urchin
plush dew
#

Or search google to see how others solved it

glad urchin
#

Ok, yea I'll do that

plush dew
#

I'm getting hungry now, so my brain is shutting down 😅
For any new questions, best ask the channel.
I'm barely equipped to help you with this, since it has been so long since I actually coded a game

glad urchin
#

Hey no problem, thanks for the help!

plush dew
#

You're welcome. Good luck.
And try to make your next issue explained within a single post, with resources linked.
That will make it easier for people to pick up on your issue.