#Rotation and Movement
1 messages · Page 1 of 1 (latest)
that video is a detailed showcase of a problem, if you'd like to see just what's wrong with the rotations and speed you can skip to 2:20
Rotation and Movement
Have you followed some guide on Movement and Rotation using Coroutines?
what?
I am not trying to make movement
it's just called rotation and "movement" because it's moving too so I didn't know what else to name it
Alright. Explain what mechanic you're working on, and what the problem is.
I showed the whole thing in a video that explains it far better than words can but sure.
I am trying to apply a constant rotation a ig you could call it acceleration or whatever to that object
I need it to happen in exactly one second so let's say that rotation speed Z is 30, I need it to rotate on a Z axis in exactly one second
same goes for movement but instead of rotating I need it to move for that amount in a second
I would like to avoid all of this being in an Update loop since coroutines are just much cleaner and easier to reuse and stuff
I recently had a conversation with someone much more experienced than myself, and I voiced my interest in exploring Movement based on Coroutines, but was told emphatically that it would be using a tool in a way it was not meant, and in a way that is overly complicated, and in a way that is ultimately not necessary.
Since you have set this up already, I'm not going to dissuade you. That's up to your own judgement.
However, I can't imagine anyone here will be able to help you, unless you spam this issue for a week.
I have no special confidence that I can help you solve this, unless you want to rewrite the thing to work in the update loop.
Yet, I have some questions and a few things to point out.
Sure, I can do it in an update loop but that's say 100 more Update loops/beat
this script is attached to every object so that's a lot more Update loops which I am not sure is too performant
coroutines on the other hand are ran on other threads from what I know
// Can only be stopped by StopAllCoroutines()
StartCoroutine(Move());
// Can be stopped
private IEnumerator DoMove;
//...
DoMove = Move();
StartCoroutine(DoMove)
How many objects?
or, I could just assign a Move coroutine to a new coroutine variable and stop it from there
although I don't see a reason for it since the object should be moving pretty much it's whole lifetime
well that's up to a user creating the level
You can store a Coroutine type reference from the return of StartCoroutine() yes
IEnumerator is a more prepared approach. (doesn't matter)
but some levels in geometry dash have millions of objects so I guess this game would have at least 1000-10000 at most ig
Well, unless you are already experiencing issues, optimization should come last.
What I wonder is, are coroutines really more efficient?
In some scenarios they could, but you seem to be running them every frame either way, and for visual changes it makes sense to do just that.
Is there something I'm missing?
@errant spire
ig I'll do it in the update but I ran in the exact same issue in update as I said earlier
but sure let's do that again because everyone is telling me to do it even tho I said it's not working
Alright, last two things tho:
will let you know when I rewrite the code and see if anything changed
inside the Move and Rotate coroutines,
inside and at the end of the while loop, yield return new WaitForEndOfFrame, I think that essentially brings you to LateUpdate()
And after the while loop, there is yield return null which is normal to use in a coroutine, when suspending it until the next frame.
goto Beginning will never run, and doesn't have to be there.
Long story short, I believe you could shorten the existing code by removing the first and last two lines in the coroutines, and changing yield return new WaitForEndOfFrame into yield return null;
Alright. Good luck o/
@errant spire
No need for a coroutine on this one.
Destroy(gameobject, levelObject.levelObjectStats.lifeTime)
thanks for noticing
aaand guess what... there goes another 15 minutes I am not getting back...
it's exaactly the same
like if I didn't change anything at all
I would really appreciate somebody helping me with this
not sure if this is just me but the video I sent is gone, just in case, here:
https://youtu.be/Bei8Ij6fsn8
the bottom line doesn't really make sense to me. You are lerping from current rotation to target rotation, with lerpAmount which is in range 0..1?
maybe you want something like
transform.rotation = Quaternion.Slerp(originalRotation, Quaternion.Euler(targetRotation), lerpAmount);
and originalRotation would be the default/zero rotation you want for that object.
@errant spire
if I am not wrong, lerp works by getting a value between x and y depending on z which I named lerpAmount
so I am resetting it to 0 every time it gets to 1 and changing the target position to a new one by doing t.pos + lvlObjS.speed
same goes for rotation
I know what youre trying to do
how is that code any different other than using Quaternion.Slerp instead of v3.lerp
You usually lerp like this:
var currentValue = Mathf.Lerp(startValue, endValue, t);
where t is in range 0..1.
OR:
currentValue = Mathf.Lerp(currentValue, targetValue, speed * Time.deltaTime);
you are currently doing a mix of both. And it wont work.
that might be what's causing the rotations to go crazy when they hit -0 but still doesn't solve the problem where it just gets paused for a second after each lerp
you arent currently lerping from originalRotation. you are lerping from current rotation.
oh... I somehow managed to completely miss that
here i explained your flaw as good as i can i think
let me correct that mistake, it'll prob fix one part of the problem but not sure about the pause
Idk anything about any pause, just looking at your rotation code
I got it from the last message when you said that I am lerpig from curr instead of orig rot
sent a video, skip to 2:20
no idea what im looking at 🤷♂️ words would be cool.
well the object moves as it should from point a to b but instead of finding a new point b and continuing it freezes for a sec and then continues
Wanted to add: using Vector3.Lerp with euler angles will not work like you think it will. It should be used with positions only
same happened with rotation
yeah talking about positions now, didn't know quaternion.slerp existed till now
so did you try this yet?
@errant spire
take 1 problem at a time
had to get on my pc doing it rn
so yeahh... this somehow managed to fix all of the problems
somehow?
I explained everything you did wrong
I do get how doing Quaternion.Slerp would fix rotations going crazy but the part where it just froze for a second after moving from point a to point b being fixed doesn't make sense to me at all
yeah I know where I messed up but I don't know how it solved this problem
well your way of lerping the rotation was fundamentally wrong 😅
I might just be too tired to think I don't know, in any case thanks a ton!
yeah that part completely makes sense to me the other one doesn't
in case you still wonder what was wrong, look at this
you mixed those two methods
of lerping
yes I do know, I didn't store my starting value(which I am doing now) but I don't get how storing it fixed the object staying in place for a second after reaching point b
I don't wanna bother you with it you must have something else to do, as I said thanks a ton for helping me solve this!
yeah np 👍