#How would i make a LinearVelocity that goes away from a specific object
1 messages · Page 1 of 1 (latest)
Shoot I responded to your other thing but depending on how you have everything set up you could try raycasting to the wall and set velocity to the normal of the result * force
in the wall jump script or
that just removes all the horizontal momentum
i dont really know how to make a raycast
https://create.roblox.com/docs/workspace/raycasting theres a pretty good roblox guide about raycasting might be worth a look
Also when raycasting be careful about whitelisting/blacklisting the correct parts so you dont pick up junk
yea i already tried that
it just gets rid of all the horizontal movement because its such a low number
im gonna try sand's idea
Goodluck
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
** You are now Level 11! **
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
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 😭
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
Nice got it all working?
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
Can we see the updated code
and ngl Imma go to sleep Ill continue helping in the morning 😭🙏
Thats one way to do it are you using ray result at all?
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
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
the unit of the raydirection?
or something else\
ima just save this and work on it tomorrow
isn’t it now .Exclude not .Blacklist
What are you trying to say 😭
Yes, and multiply that by a set force and that should give you the same amount of force regardless of wall size
Combine the hrp look vector with the wall look vector
they already got it kinda working look
!
Ah
ok im back now im gonna try to do some of the things u guys suggested
would the set force just be a flat number?
what does hrp stand for again sorry
oooh humanoidrootpart
yes
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
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
thamks
Goodluck keep me updated
how do i do the abs thing
is it part of the raycast result or direction
abs?
Oh thats what I meant I was talking about the Unit vector
does this work already?
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
** You are now Level 8! **
wow Im getting old
basically the same issue, regardless of if it's rayresult or direction
-30 might not be enough try like -300
keep walljumpdirection as it was ray direction
just sends me flying even further, and its still effected by the size too
Can I see code and screenrecord
here code
everything before that is just variables
like userinpout service and stuff
lemme get recording
you forgot to do .Unit on the ()
= (walljumpdirection + currentwall.CFrame.UpVector).Unit * -30
oh mb
No worries 🫡 lets see if thats better
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
Wanna try raycasts 🥹
Yes
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
wait before we try raycasts try this first
= walljumpdirection.Unit * -30 + Vector3.new(0, 30, 0)
same issue as before, right velocity but wrong direction
idk if its possible but im tryna make it send you straight in the direction of the side you're on
kinda like this
I get what you're going for
oh ok thanks
should the rayorigin be something else like the wall
and then the rayend be the rootpart?
that wouldnt change anything it would just flip signs
can you do this first 😭
i know this might sound dumb but i dont really know what u mean by recaulculate
its not a dumb question its okay, but it would be a lot easier to show you if you sent me your code in text rather than image format
even if its just this part
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
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
its a bit better, it consistently goes upward now
the direction is still messed up
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
im back if ur available
i have a saved version of the script that uses raycast since were just gonna use raycast again
yo
are u able to continue rn
im ready rn if ur available
Yo sorry, didnt see these thank you for the ping
I got you
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
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
same thing
oops
Ok edited the code
local rayresult = workspace:Raycast(rayorigin, raydirection * 10, raycastParams)
this line
i think the raycast itself can detect the surface of the thing you touched
Did it do the same thing?
This was my idea with the normals lol
I would be honored
lemme just try to understand how it works
Lemme draw it out
Yes
ooooh that makes sense
cuz i was looking at examples of rays outside of coding and i figured out thats what the noraml is
Normal vector
aaah
Math helps a lot yes
so when a ray touches a surface, in bounces straight off that surface and thats what a normal is?
Calculus 3 helped me a lot
Not exactly, normal is just the direction of the face
OOOOH
so its the direction the surface it touched was facing?
imagine those arrows as the normal vectors
aaaah
Where the ray hit, its the direction where the face is looking
so the ray's normal is basically looking in the same direction that the touched surface is facing?
ok that makes sense
Yeppp exactly
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
Discord sounds good 
GlowSand/EndoTulpa works
thats both
very WIP credits cuz the game is early in development
oops typo
fixed the typo
AYEE THANK YOU