#Jumping while wall grabbing launches the player into the sky
1 messages · Page 1 of 1 (latest)
from a bit of testing it also only seams to happen when the player is not directly up against the wall.
PHYZRB.AddForce(transform.position * moveToLedgeForce, ForceMode.Impulse);```
not sure what this is supposed to be doing but using a position as a force vector is a recipe for wacky stuff
what do you mean?
Another problem here:
PHYZRB.linearVelocity = new Vector3(PHYZRB.linearVelocity.y, climbspeed , PHYZRB.linearVelocity.z);```
You're plugging y into the x field
I mean exactly what I said. transform.position as input to AddForce is crazy.
THink about what that means.
If that code runs when you're standing at world 0,0,0, it does nothing.
If that code runs when you're 100 meters away to the east, at (100, 0, 0), it will fling you to the east very quickly
basically it's going to do something wildly different depending on where in the universe you are standing when it runs
I'm not sure what your intention was with that code, but that can't be right
I actually think the second issue with plugging y into the x slot is probably causing the issue you're describing though
Oh i see. my goal with it was that it would push the player up against the wall.
you would need to calculate a direction vector from the player's position towards the wall
transform.position ain't it
ok so how would I do that.
I have working sphere cast would convert that to something.
A simple approach would be to store the hit.point from your spherecast
then you can calculate a direction vector from the player to that point with:
Vector3 direction = (spherecastHitPoint - transform.position).normalized;```
The vector from A to B is always B - A
ok thank you I try that out and I'll get back to you.
ok I'm sorry I'm still a little new to this how would I store a hit.point?
ok how would I do that.
do what
find the hit.point
oh lol I'm just over complicating it in my head
so this
wallfront = Physics.SphereCast(transform.position, sphereCastRad, Orientation.forward, out fromtWallHit, detectionLedngth, whatIsWall); ?
ok ok so something like this
Vector3 direction = (fromtWallHit.point - transform.position).normalized;
@fossil scarab ok I'm not full sure what to do with this.
ok I think I'm getting but in the documentation you sent they uses this thing called ray. what is it. it doesn't say anything on it.
you're already doing your spherecast
you're gettign confused by their example
the whole point of the example is to show that you can use hit.point, that's all
you can ignore the rest of it
in your code you named the RaycastHit something else though
so naturally you would use that
ok so this is correct
Vector3 direction = (fromtWallHit.point - transform.position).normalized;
then i take the "direction"
and use it like this?
fromtWallHit.rigidbody.AddForce(???.direction * moveToLedgeForce, fromtWallHit.point);
@fossil scarab
It seems to me like you're still struggling with the basics of C#
that's going to make it kinda hard to do this stuff
sort of... but you need to learn how to use variables and call methods.
You should look at what parameters AddForce takes as well
ok so then what would I put in the "???" spot I tried my raycast and that didn't work.
why do you need something in the ??? spot
you need to store the position in a variable
and then just use the variable
because it wants something there.
You would either use a field: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/fields
Or pass the variable around as a method parameter: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods
you're getting confused because you don't understand variable scope
you can't use a variable from another scope like that directly
I get what a field is I understand methods.
I'm just confused what I need to be doing.
ok let me just start form the top. I'm sorry this is a struggle for me I just can't learn from just reading I need to actually do it.
So this " wallfront = Physics.SphereCast(transform.position, sphereCastRad, Orientation.forward, out fromtWallHit, detectionLedngth, whatIsWall);" is my hit.
I take this wallfront and use it like this
"Vector3 direction = (fromtWallHit.point - transform.position).normalized;"
Right?
fromWallhit is the RaycastHit
you should extract the point from it and store that in a variable
e.g.
myVariable = fromtWallHit.point;```
Then later:
Vector3 direction = (myVariable - transform.position).normalized;```
thank you.
the variable will need to either be a field, or passed via method parameters to be used in the other method
ok I got that. So then next I would just mimic this
"hit.rigidbody.AddForceAtPosition(ray.direction * pokeForce, hit.point);" from the docs
is there a reason you want to use AddForceAtPosition now?
Your original code was just using AddForce
oh no thanks for catching that.
The example code from the docs were just showing you that hit.point exists basically. The entire rest of it is just an example that you don't want to copy unless you happen to be doing exactly what the example was doing
which you aren't
its defiantly smother but still its launching the player up.
There's no command called
cod.
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
cs
see the large code blocks section.
{
//refrances
public Transform Orientation;
public Rigidbody PHYZRB;
public LayerMask whatIsWall;
public PlayerMovement pm;
//climbing
public float climbspeed;
public float MaxClimbTime;
public float climbingTimer;
public bool climbing;
public KeyCode ledgeGrab = KeyCode.G;
public KeyCode wallMoveUp = KeyCode.W;
//moveto ledge force
public float moveToLedgeForce;
//Wall detection
public float detectionLedngth;
public float sphereCastRad;
public float maxWallLoookAngle;
private float wallLookAngle;
private RaycastHit fromtWallHit;
public bool wallfront;
public bool wallleft;
public bool wallright;
public bool wallPointHit;
public Vector3 wallHitVar;
public float wallPointLocation;
//
float horizontalInput;
float verticalInput;
void Update()
{
WallCheck();
Vector3 direction = (wallHitVar + transform.position).normalized;
if (Input.GetKeyDown(ledgeGrab) && wallfront == true)
{
PHYZRB.AddForce(direction * moveToLedgeForce , ForceMode.Impulse);
StateMECH();
}
else if (!wallfront == true)
{
climbing = false;
return;
}
if (climbing && Input.GetKeyDown(wallMoveUp))
{
clmbingmovement();
}
}
private void StateMECH()
{
//when to start climbing
if(wallfront && wallLookAngle < maxWallLoookAngle)
{
if(!climbing)
{
startclimbing();
//timer
if(climbingTimer > 0)
{
climbingTimer -= Time.deltaTime;
if(climbingTimer < 0) stopClimbing();
}
}
}
//state none
else
if(Input.GetKeyDown(ledgeGrab) && climbing)
{
PHYZRB.useGravity = true;
stopClimbing();
}
//you are HERE!
}
}
private void WallCheck()
{
wallfront = Physics.SphereCast(transform.position, sphereCastRad, Orientation.forward, out fromtWallHit, detectionLedngth, whatIsWall);
wallleft = Physics.SphereCast(transform.position, sphereCastRad , -Orientation.right, out fromtWallHit, detectionLedngth, whatIsWall);
wallright = Physics.SphereCast(transform.position, sphereCastRad , Orientation.right, out fromtWallHit, detectionLedngth, whatIsWall);
//the madness that is found at 5:15 AM is a madness only I hold.
wallLookAngle = Vector3.Angle(Orientation.forward, -fromtWallHit.normal);
wallHitVar = fromtWallHit.point; // The point of no return
//You are here
if (wallfront == true)
{
Debug.Log("HAY I SEE A WALL.");
}
if(pm.isGrounded)
{
climbingTimer = MaxClimbTime;
}
}
private void startclimbing()
{
climbing = true;
}
private void clmbingmovement()
{
PHYZRB.linearVelocity = new Vector3(PHYZRB.linearVelocity.x, climbspeed , PHYZRB.linearVelocity.z);
PHYZRB.useGravity = false;
}
private void stopClimbing()
{
climbing = false;
PHYZRB.useGravity = true;
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
}```
you didn't save the paste
its not letting me save it.
A tool for sharing your source code with the world!
ok dose this work
yes
now, what's the current issue? is it still the same issue of launching the player up?
yes thats the main issue
well, this script only affects the rigidbody in 2 places
if you comment one or the other out, do you still get launched?
if you do, then the cause isn't in this script - it may be something else that is kinda fighting this one
what do you mean two places?
do you mean the PHYZRB.AddForce(direction * moveToLedgeForce , ForceMode.Impulse);
yes, that and setting the velocity on line 134
i meant to mention them and forgot, mb
ok so I did disable one and I was still dealing with the issue.
and what if you disable the other?
the one at 134
(and do make sure you're saving & compiling when testing)
what about it
oh sorry I'll check
Vector3 direction = (wallHitVar + transform.position).normalized;
this doesn't seem right
a vector from A to B looks like B - A, not B + A
I tried that but when I did I would move backwards.
ok and when I do the one at line 59 the player dose not move to the wall.