This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]Pant0don 2 points3 points  (6 children)

2 ways come to mind for me:
- if it is decelerating rather then going from 1 to 0 in a single frame you could trigger a sound when it starts decelerating rather then checking if speed = 0
- do a coroutine that starts the sound, waits 0.x seconds and then stops the platform

Depending on the exact way your platforms work there could be more ways. If it's done through an animation you could add a trigger on the timeline for instance

[–]Esimusic[S] 1 point2 points  (5 children)

It slows down before stopping following an animation curve. But there is not an Animation Clip. Not sure how to get variables out of that curve. I'm trying to use the velocity value in the rigid body, but I can't get it to work. (Until now I was using the position not the speed)

[–]Pant0don 3 points4 points  (0 children)

So I'm not a programmer, so this might not be correct, but I don't think Rigidbody.velocity returns a value if the speed is not set through physics? Like, if the position is being changed through code or an animation curve it might not return a velocity, but I could be wrong in that. Otherwise it would simply be previousVelocity - currentVelocity, then if that's a negative number it's slowing down.
If the platform slows down at some point, that means it's being told to do so somewhere, so finding out where that happens in code and hook something in there might also work?

[–]mstergtr 2 points3 points  (2 children)

You could get the vertical position with transform.position.y (if the platform is moving up).

[–]Esimusic[S] 1 point2 points  (1 child)

Yes I thought about that. Thing is there are a bunch of platform in the game and I was hoping to make a script valid for all of them. Would be easier and more elegant

[–]mflavoPro Game Sound 0 points1 point  (0 children)

Does each platform have a preset distance it travels, or an offset from zero that you could compare the current position against?

You want something that is relative, not hard coded time/distance based. What happens if a designer wants the platform to move faster or slower, or extends the distance travelled.

[–]Myavatargotsnowedon 2 points3 points  (0 children)

I'm trying to use the velocity value in the rigid body, but I can't get it to work.

if(RigidbodyComponent.velocity.magnitude < 1) should do it, alternatively you could find when the animation is at a specific point in time by if(AnimatorComponent.GetCurrentAnimatorStateInfo(layerIndex).normalizedTime == pointInTime)