#How would i make a LinearVelocity that goes away from a specific object

1 messages · Page 1 of 1 (latest)

celest monolith
#

its cuz im trying to make a wall jump, but i tried to use the lookvector of the wall but it will only launch me in the direction that the wall is looking, so i need it to be able to launch me away from the wall not just in the direction its facing but idk how to do it.

#

currentwall is the object im trying to make the velocity launch away from

river wasp
#

try multiplying the walls look vector by -1

#

lmk if that works

#

@celest monolith

grand sparrow
celest monolith
celest monolith
celest monolith
grand sparrow
river wasp
#

the top line do * -1

#

(click in the image i sent)

#

if this is what you did then nvm

grand sparrow
#

Also when raycasting be careful about whitelisting/blacklisting the correct parts so you dont pick up junk

celest monolith
#

it just gets rid of all the horizontal movement because its such a low number

#

im gonna try sand's idea

grand sparrow
#

Goodluck

celest monolith
#

thanks

#

but to create the raycast in the right direction i would need some way to tell the code to put it in the opposite direction of the wall

tropic notchBOT
#

studio** You are now Level 11! **studio

celest monolith
#

so i need a way to make it basically

#

go away from the wall

#

but idk how to detect that in code

#

i just need a way for a cframe/vector 3 to point away from a certain object

grand sparrow
#

You need to make it shoot to the wall, and when it detects a hit to the wall it will return some values along with the hit normal, the hit normal points away from the wall

#

Imagine red is the wall, and blue is the normal vector

#

I can try drawing something out or explaining it a little better if needed btw 😭

celest monolith
#

hmm ok

#

i tried to make a raycast with the humanoidrootpart position that goes to the wall's position, but it made this error

#

nvm i forgot to put .position after hit

#

my fault lemme try again

#

ok there was no error so i beleive the raycast was created, its just not visible cuz i dont think raycasts are visible by default

#

does the raycast need a parent to be visible or something

#

added direction to it and tried to print the raycast result but it made this error:

#

nvm i wasnt supposed to put rayend into the result

#

now it works

grand sparrow
celest monolith
#

lemme record

thorny niche
#

lmao

#

oh

#

i wasnt looking at the right message

#

😭

celest monolith
#

the main problem is that it gets screwed up when you use it on a flatter wall

#

most likely because it makes the raycast smaller

grand sparrow
#

Can we see the updated code

#

and ngl Imma go to sleep Ill continue helping in the morning 😭🙏

celest monolith
#

here

grand sparrow
celest monolith
#

if i use rayresult instead of raydirection it make this error

#

lemme find it

grand sparrow
#

It doesnt return a vector or a number it returns this

#

.Normal should help you also please read that article it explains how to blacklist stuff so raycast wont be blocked by your player

grand sparrow
# celest monolith

Another way you could do is get the unit vector of what you’re doing rn and multiply it by a set amount that way it will always be the same

celest monolith
#

or something else\

#

ima just save this and work on it tomorrow

river wasp
grand sparrow
grand sparrow
high quarry
grand sparrow
grand sparrow
high quarry
celest monolith
#

ok im back now im gonna try to do some of the things u guys suggested

celest monolith
celest monolith
#

oooh humanoidrootpart

grand sparrow
celest monolith
#

wouldnt this already be a set forrce

#

or do i do all this + a set force

#

yea i tried adding a set force typa thing but the same problem still happens

#

if u do it against the flat part of a wall u get no distance

#

yo

#

@grand sparrow

grand sparrow
#

Thats not normalized

#

When you normalize a vector all of its components add up to 1 and when you multiply by a scalar force you should always get the same magnitude

#

Ah mb I forgot roblox calls it unit vectors they are the same thing

#

@celest monolith

celest monolith
#

thamks

grand sparrow
celest monolith
#

is it part of the raycast result or direction

grand sparrow
celest monolith
#

this thingy

#

or is it not even part of the raycast

grand sparrow
#

Oh thats what I meant I was talking about the Unit vector

grand sparrow
celest monolith
#

kinda

#

the direction and velocity are still messed up by the size

grand sparrow
#

try


= (walljumpdirection + currentwall.CFrame.UpVector).Unit * -30

keep in mind you're probably gonna have to change -30 a bit until it works but it shouldnt be messed with size anymore

#

Also as you dont end up actually raycasting or using "rayresult" Id suggest deleting raycast for performance

tropic notchBOT
#

studio** You are now Level 8! **studio

celest monolith
#

basically the same issue, regardless of if it's rayresult or direction

grand sparrow
#

keep walljumpdirection as it was ray direction

celest monolith
#

just sends me flying even further, and its still effected by the size too

grand sparrow
#

Can I see code and screenrecord

celest monolith
#

here code

#

everything before that is just variables

#

like userinpout service and stuff

#

lemme get recording

grand sparrow
#
= (walljumpdirection + currentwall.CFrame.UpVector).Unit * -30
celest monolith
#

oh mb

grand sparrow
#

No worries 🫡 lets see if thats better

celest monolith
#

ok the velocity is consistent now, i just need to get the direction to be consistent

#

lemme send recording

#

wait nvm im stupid its just the same

#

if i go to the center of a flat shape theres just no distance

grand sparrow
#

Wanna try raycasts 🥹

celest monolith
#

it already uses a raycast

#

are u talking about rayresult?

grand sparrow
#

Yes

celest monolith
#

instead of raydirection

#

lemme try that

grand sparrow
#

No

#

Can you send your code formatted like

```lua

[code]

```

like this please

celest monolith
#

whoa

#

ok its weird to type like that

#

i might have been wrong earlier
i think its the right velocity with the raydirection
it just looks bad cuz the actual direction you get flung in isnt in the normal arc of a jump

#

its the right velocity i just need to get it in the right direction

#

just like

#

make the ray point upward away from the wall or something

grand sparrow
#

wait before we try raycasts try this first

= walljumpdirection.Unit * -30 + Vector3.new(0, 30, 0)
celest monolith
#

idk if its possible but im tryna make it send you straight in the direction of the side you're on

#

kinda like this

grand sparrow
#

recalculate this part

#

right before here

celest monolith
#

oh ok thanks

celest monolith
grand sparrow
#

that wouldnt change anything it would just flip signs

grand sparrow
celest monolith
grand sparrow
#

even if its just this part

celest monolith
#

ok lemme try

#
RootPart.Touched:connect(function(hit)
    if debounce == false then
        if hit:HasTag("Wall") then
            print(hit)
            debounce = true
            RootPart.Anchored = true
            currentwall = hit
            print(currentwall)
            local rayorigin = RootPart.Position
            local rayend = hit.Position
            local raydirection = rayend - rayorigin
            local rayresult = workspace:Raycast(rayorigin, raydirection)
            print(rayresult)
            walljumpdirection = raydirection
        end
    end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.Space then
        if debounce == true then
            RootPart.Anchored = false
            --RootPart.Velocity = currentwall.CFrame.LookVector * 70 + currentwall.CFrame.UpVector * 70
            --RootPart.Velocity = walljumpdirection * -3 + currentwall.CFrame.UpVector * 70
            --RootPart.Velocity = (walljumpdirection + currentwall.CFrame.UpVector).Unit * -100
            RootPart.Velocity = walljumpdirection.Unit * -60 + Vector3.new(0, 60, 0)
            task.wait(.1)
            debounce = false
        end
    end
end)
#

there

grand sparrow
#

thank you

RootPart.Touched:connect(function(hit)
    if debounce == false then
        if hit:HasTag("Wall") then
            print(hit)
            debounce = true
            RootPart.Anchored = true
            currentwall = hit
            print(currentwall)
        
        end
    end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.Space then
        if debounce == true then
            local walljumpdirection = currentwall.Position - RootPart.Position
            RootPart.Anchored = false
            --RootPart.Velocity = currentwall.CFrame.LookVector * 70 + currentwall.CFrame.UpVector * 70
            --RootPart.Velocity = walljumpdirection * -3 + currentwall.CFrame.UpVector * 70
            --RootPart.Velocity = (walljumpdirection + currentwall.CFrame.UpVector).Unit * -100
            RootPart.Velocity = walljumpdirection.Unit * -60 + Vector3.new(0, 60, 0)
            task.wait(.1)
            debounce = false
        end
    end
end)
#

try this

celest monolith
#

its a bit better, it consistently goes upward now

#

the direction is still messed up

grand sparrow
#

nvm I get the issue 😭 turns out we are gonna need raycasts after all

#

walljumpdirection calculates to the center not where the collision happened lets continue this tomorrow Im gonna head to bed 3 am where Im at

celest monolith
#

ok

#

goodnight thannks for the help

celest monolith
#

im back if ur available

#

i have a saved version of the script that uses raycast since were just gonna use raycast again

celest monolith
#

yo

celest monolith
grand sparrow
#

I got you

celest monolith
#

ok lemme load studio up

#

ok

#

here's the system i have rn

#

i guess we gotta figure out a way to get a consistent direction, the velocity is fine

#

how can we like
make the raycast go consistently in the direction of the wall and not just a straight ray from us to the wall

#

is there a way to detect the surface of the thing u touched

grand sparrow
#

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include

RootPart.Touched:connect(function(hit)
    if debounce == false then
        if hit:HasTag("Wall") then
            raycastParams.FilterDescendantsInstances = {hit}
            print(hit)
            debounce = true
            RootPart.Anchored = true
            currentwall = hit
            print(currentwall)
            local rayorigin = RootPart.Position
            local rayend = hit.Position
            local raydirection = rayend - rayorigin
            local rayresult = workspace:Raycast(rayorigin, raydirection * 10, raycastParams)
            walljumpdirection = rayresult.Normal
        end
    end
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.Space then
        if debounce == true then
            RootPart.Anchored = false
            RootPart.Velocity = walljumpdirection * 60 + Vector3.new(0, 60, 0)
            task.wait(.1)
            debounce = false
        end
    end
end)

just balled this try it

celest monolith
#

same thing

grand sparrow
#

oops

#

Ok edited the code

local rayresult = workspace:Raycast(rayorigin, raydirection * 10, raycastParams)
#

this line

celest monolith
#

i think the raycast itself can detect the surface of the thing you touched

grand sparrow
#

Did it do the same thing?

celest monolith
#

holy shit i think you did it

#

lemme record

grand sparrow
celest monolith
#

i gotta put you in the game's credits atp

grand sparrow
#

I would be honored

celest monolith
#

lemme just try to understand how it works

grand sparrow
#

Lemme draw it out

celest monolith
#

is the normal like

#

the part where the ray bounces off

#

of the wall

grand sparrow
#

Yes

celest monolith
#

ooooh that makes sense

grand sparrow
celest monolith
#

cuz i was looking at examples of rays outside of coding and i figured out thats what the noraml is

grand sparrow
#

Normal vector

celest monolith
#

aaah

grand sparrow
#

Math helps a lot yes

celest monolith
#

so when a ray touches a surface, in bounces straight off that surface and thats what a normal is?

grand sparrow
#

Calculus 3 helped me a lot

grand sparrow
celest monolith
#

OOOOH

grand sparrow
#

I wish I was better at drawing

#

found this online tho

celest monolith
#

so its the direction the surface it touched was facing?

grand sparrow
#

imagine those arrows as the normal vectors

celest monolith
#

aaaah

grand sparrow
celest monolith
#

so the ray's normal is basically looking in the same direction that the touched surface is facing?

#

ok that makes sense

celest monolith
#

ok lemme add the credits of the game cuz i lowkey havent done that yet

#

for ur part of the credits do u want ur roblox username or ur discord

#

@grand sparrow

#

if u wanna be in the credits

grand sparrow
#

GlowSand/EndoTulpa works

#

thats both

celest monolith
#

very WIP credits cuz the game is early in development

#

oops typo

#

fixed the typo

grand sparrow