#Handling Moving Platforms with my player.

1 messages · Page 1 of 1 (latest)

tawny marsh
#

hello.

#
if (hit.rigidbody != null)
{
var TargetVel = hit.rigidbody.GetPointVelocity(hit.point);

rb.linearVelocity += TargetVel - LastPlatVel;

LastPlatVel = TargetVel;
{
wispy frigate
#

you gotta show more context than this, man

#

!code

clever kernelBOT
tawny marsh
wispy frigate
#

you've been showing detached sections of code

#

we need context on how the code flows

tawny marsh
#

this is all the player code that handles the platform stuff, as i said before i am using a floating rigidbody.

wispy frigate
#

where do you apply velocities, what leads up to that, what message is the code in

tawny marsh
wispy frigate
#

we need the surrounding code

#

what method is this in

#

what is hit from

tawny marsh
wispy frigate
#

just send the whole method or the whole script if you can't figure out which parts are relevant

tawny marsh
wispy frigate
#

ok so the answer to this

the moment the player gets on - is the platform's existing velocity applied?
is that baked into the delta check?
was apparently that it's baked into the delta check

#

if you aren't doing any collision messages, i guess

wispy frigate
#

what's the actual behavior currently, then

#

you're really leaving me guessing here

tawny marsh
wispy frigate
#

a description of what happens to the player on the platform

#

a video, perhaps

#

what's the actual issue currently

tawny marsh
# wispy frigate a description of what happens to the player on the platform

a raycast is shot down from the player, it then checks the velocity of the platform at that point using GetPointVelocity(hit.point) then applies that velocity directly(this is changing alot as i'm trying to find the best method to apply the velocity to stop the issues i'm having). p.s if that doesn't help i'll send a video.

wispy frigate
#

yeah that really isn't what i asked at all lmao

tawny marsh
#

wasn't that a "a description of what happens to the player on the platform"?

wispy frigate
#

nope, that's what the code does

#

that's not what actually happens to the player

#

i'm asking, what is the issue

tawny marsh
#

what happens is that any time the platform experiences a large velocity change the velocity applied tends to spike unnaturally.

wispy frigate
#

so is the player actually tracking the platform through small velocity changes then?

wispy frigate
#

bro that's the thing you were complaining about earlier 💀

#

you gotta get better at providing info

tawny marsh
wispy frigate
#

so what's actually happening with the large velocity changes

#

just.. send a video

wispy frigate
#

sooo it wasn't tracking through small velocity changes at all?

tawny marsh
wispy frigate
#

would also help if you removed the search and let the logs scroll so we could actually see the difference in velocity each tick

#

also perhaps debug the player velocity in comparison to the platform velocity

#

also check if the player has damping or anything like that

tawny marsh
wispy frigate
#

exactly why i said to let the logs scroll

#

disable your other irrelevant logs for now

tawny marsh
#

btw it's showing the hit.rigidbody.GetPointVelocity(hit.point)

wispy frigate
#

keep the previous log of the delta values, and log this velocity and the player velocity

wispy frigate
#

also, just to make sure - you aren't moving when you're on the platform, right

wispy frigate
tawny marsh
#

i'm applying the velocity like this rb.linearVelocity += PlatVel;

wispy frigate
#

whyy

wispy frigate
#

stop making random changes

tawny marsh
wispy frigate
#

were they actually not moving the player or did you just think they were too small
.01 of acceleration per tick is normal, that's 0.5 of acceleration per second

tawny marsh
#

i am applying that velocity to the player.

wispy frigate
#

show that

wispy frigate
#

and what are you logging there

#

man i'm not psychic

tawny marsh
wispy frigate
#

ok man just show the code

#

im not playing this game of 20 questions

bitter slate
#

it'd work better but i had a floating suspension and spring setup on my rigidbody

bitter slate
# bitter slate

Platform Basics

  • Detecting a platform: Check if the player is standing on one (e.g., raycast or collision).
  • Getting platform velocity: Ask the platform how fast it’s moving (GetVelocity() method).
  • Adding platform velocity: Combine the platform’s movement with the player’s own movement.
  • Leaving the platform: Stop adding the platform’s velocity when the player steps off.

Example Psuedo Code

Vector3 velocity = playerInput;

if (onPlatform)
{
    velocity += platform.GetVelocity();
}
rb.velocity = velocity;
  • playerInput = your normal movement
  • platform.GetVelocity() = the platform’s motion
  • combine them so the player moves with the platform
#

Tips:

  • Frame timing matters: always use FixedUpdate() for physics. so platform and player velocities stay in sync.
  • Floating/ non-colliding players: if ur player doesn't physically touch the platform use raycasting or check distance
  • Vertical motion: if the platform moves up and down you need to apply its vertical velocity too or the player will appear to float in place or fall through
  • Smoothing: platforms can jitter the player if velocity is applied raw.. Lerp or smoothing can help, especially for small or fast moving platforms
  • Leaving the platform; Always clear the platform reference and the velocity you were adding (this keeps the player from keeping any of the residual velocities)
  • Scaling and Rotation: If a platform rotates or scales, its velocity may need to be converted to world-space

thats about all I got.. ( i can show some of the code i used [in this test](#1428033349997297725 message) but its basically summed up by [this example code block](#1428033349997297725 message)

Good luck,
SpawnCamp† — your friendly Unity prototyper 🕹️

wispy frigate
bitter slate
#

you mean like if they were using AddForce instead?

wispy frigate
#

yeah

bitter slate
#

ohh crud

#

yea for that first thing comes to mind is temporarily attaching it as a child..

#

and overhauling the movement code to work in local spaces

#

oh yea, i hadn't even thought about that.. i just recalled he was using a rigidbody.. and I was also using a rigidbody for my current prototype...
went through all that work to implement platforms and i don't even need em 😬

wispy frigate
bitter slate
# bitter slate

anyway, even if it is the wrong type of movement (i directly control my velocities...) here's a revised version of the code i have in that video..: https://paste.myst.rs/w2q2l8la

figure'd i'd just go ahead and paste it anyway since i wrote it out
-# 💡 there still may potentially be something useful in there for ya

bitter slate
#

i have spring forces.. soo thats why there seems to be a bit of lag in directional changes in the example video up there ☝️

but if i disable the springs it works pretty reliably

#

❕ i keep the platforms velocity in a totally different cached variable
so i can nuke it off the velocity when exiting the platform
that was the only issue i had in that implementation ^ but idk if its foolproof**

wispy frigate
#

though there is a concern i have - without SEO/latefixedupdate, wouldn't this make the player lag behind the platform by a tick

#

probably not gonna be enough to be relevant, but hey, it's there (i think)

bitter slate
#

i dont have any jitterying or anything also b/c i was using a spring-based groundcheck

#

player doesn't even technically touch the ground... soo the platform never gets a chance to clip or anything like that

bitter slate
#

i don't have a rb that uses forces tho 🙁

#

i would imagine u could just do the same concept.. but before the addforce call..

wispy frigate
#

it might happen before the simulation tick, where i think accumulated forces are turned into velocity?

tawny marsh
#

my current solution rn is to use rb.MovePosition but that's jittery and doesn't really have the physically that i want.

#
rb.MovePosition(TargetPos);```
vale arch
#

For moving platforms, I reparent to the platform then move players local position/rotation

tawny marsh
vale arch
#

You could handle the physics manually. Or you could use physics joints to attach to the platform

tawny marsh
vale arch
#

I havent had any issues with reparenting. If the player jumps or collides with anything you can immediately unparent

tawny marsh
vale arch
tawny marsh
bitter slate
#

u figured this out yet beggam?

#

turns out my implementation may have some lag during directional changes...

i left my player standing on top of it for about 3 hours and it never fell off.. but it does seem to lag behind when it changes directions..
(i contributed it to my spring setup on my player but i actually don't believe thats it)

#

actually.. funnily enough i seem to have gottten rid of it by tweaking the spring's dampening forces..

(red being the one thats just taking the platforms vel and adding it to itself)
(green is just a normal controller thats ignoring the platform forces)

#

its not perfect.. but for basic elevators and things i think it'd be just fine.. (especially once the camera smoothing is implemented for the player..)
i doub't u'd notice it

lavish veldt
#

I didnt read all the comments, but there is a moving platform in this one maybe check that

bitter slate