#Lerp or Lagging Constraint
1 messages · Page 1 of 1 (latest)
i'm having trouble getting my head around this right now
how would i go about updating the position of the light and the player every frame?
and in what format?
are you using transform.position to move your player?
the player movement is just rb.AddForce whenever the player inputs something
rb being Rigidbody ofc
ok so then I think that you can put lerp in your update method to make it move the light each frame
in the script for controlling the ball i presume?
ill try putting something together and see how it works
actually the lerp should be in a script on the point light
I'm not sure if this will help much, but this is kinda what I would do
void Update()
{
transform.position = Vector3.Lerp(transform.position, player.transform.position, 0.5f);
}
ignore discords formatting lol
hmmm
just that alone seems to make the light follow the player exactly
and at the same point as the player
mabye try increasing the 0.5f, I just used that as an example, but it could probably be quite a bit bigger
no change
{
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.Lerp(transform.position, player.transform.position, 5f);
}
}
current script for the light, just in case ive made some obvious mistake
hmm, I'm not really sure, just trying something random here but mabye the number needs to be small
sry it's been a really long time since I've used that
np, that still didnt seem to work though
in the documentation it seems to require an "interpolation ratio"
but i guess it isnt really important since you can just input any float so i dunno
hang on, I have an object with that function, I'm just gonna mess around with it a bit and see if I can figure something out
alright, much appreciated
worst case scenario i can just use a parent constraint with lower weight and move the light to the middle of the level or something
will have a somewhat similar effect albeit not as cool
wierd, for me, I put it to a really small number like .05f and it seems to be working
that's what i currently have it at
also I don't know if it makes a difference, I tried them both and they both seem to work for me, but I noticed that I was originally using Slerp not Lerp
ah
well
ill give it a try?
no difference :(
are you sure that's all you did? is there nothing in the script that you control your ball with?
sry, I really just don't understand why it's not working
maybe im calling the position of the player wrongly ?
:( thanks a lot for your help anyways
I notice that for player you have a gameobject and I just have the transform but that shouldn't be making a difference
oh nvm
wait
actually
maybe it is working
wait nevermind, for some reason it slowed the ball down?
i.e the player
oh that's wierd
but that means it's having some effect
ill try switching the transforms around
nope, still slowing down the ball
is there mabye a rigidbody on the light?
nope
nope, it's on it's own
nvm
shame, i feel like it's close but i just dunno how it works
yeah I wish I understood it a bit better
I doubt this is affecting anything, but kinda the only other thing I'm noticing is that mine is in LateUpdate() instead of Update()
im surprised that that didnt work
I guess there are a few other differences that I didn't mention because mine is for a camera, but I'll just post all my code
public Transform followObject;
public Transform lookAtObject;
public float smoothFactor = 0.5f;
public bool lookAtTarget;
// Update is called once per frame
void Update () {
transform.position = Vector3.Lerp(transform.position, followObject.position, smoothFactor);
transform.rotation = followObject.transform.rotation;
if (lookAtTarget)
{
transform.LookAt(lookAtObject);
}
}```
wow yea it really is that straightforward
i wonder what ive done wrong
{
Invoke("Lag", 0.1f);
}
void Lag()
{
transform.position = Vector3.Slerp(transform.position, player.transform.position, 0.5f);
}```
it just doesn't make any sense to me because I can't figure out what's different
i tried this but it didnt work either
sry what does Invoke do?
it just calls whatever function is in quotes after a certain number of seconds
Invoke("<function>", float)
as far as i'm aware at least
ah ok that makes sense
honestly even more confused that this didnt work
once the game is started, the light takes a few frames to get constrained to the ball, but after that it stays with it
and i have no idea what's going on in the background to cause that behaviour
it almost sounds like it's accelerating at the start, and then its speed never goes back down
yeah but the speed matches the ball after that
regardless of how fast it's moving
but void Lag() shouldnt be running every frame so that shouldnt be possible, right?

I honestly don't know any more lol
yeah, gonna have to give up on this for now until inspiration strikes i guess
thanks for fussing over this with me
ok
it's so wierd, I tried to stick my function on a light and it is working just fine so I have no clue what's wrong
hang on, I don't know if it's possible to do this, but could you like film it and show so I can see what's happening, because I just copy pasted your code in and it's working
the one thing I'm wondering if it has anything to do with how the ball is moving
sorry for seeing this so late
that is so strange
which bit of code did you copy exactly
ive made a few changes so i need to stick it back in
public class LightLag : MonoBehaviour
{
public GameObject player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.Lerp(transform.position, player.transform.position, .05f);
}
}```
just the original code you posted only I changed that to .05f
sry did you record this, just making sure
yeah, why?
oh I get what you mean that's what that voice is lol
I wasn't sure if it was you talking about what was happening in the game or not
oh haha
if you went into scene view instead of game view, does it look any different?
nope, light follows the ball all the same
really?
yeah! lol
maybe our scales are just different? (even though all my stuff is just scaled to 1)
I guess that would make sense, I think my character is about 3 high
hmm
well now i want do something else, which is position constrain the light to be slightly above the ball
and still have it be affected by this script
but constraining seems to take priority
right now the light stays perfectly at the ball but i want it to be above and behind (and a bit to the left)
if you look at how my other script works, you could use that
it set's an offset at the start by figuring out where it is relative to the player and then instead of moving directly to the player, it moves to the players position + the offset
🤔
im not sure what you're doing in that script exactly
is LookAt a unity thing?
or something in your own script?
oh sry, you can ignore that part, that only applies to the camera
oh i see
ohhh i see
so instead of following the ball it's following a constrained object
is a constrained object like a child object?
yea
that would probably work to, I didn't realize that when I copied the code I left removed the offset part
public Transform followObject;
public Vector3 cameraOffset;
public float smoothFactor = 0.5f;
// Use this for initialization
void Start () {
cameraOffset = transform.position - followObject.transform.position;
}
// Update is called once per frame
void LateUpdate () {
Vector3 newposition = followObject.transform.position + cameraOffset;
transform.position = Vector3.Slerp(transform.position, newposition, smoothFactor);
}```
their that includes what I meant by offset, but I think you could do a constrained object as well
ok
fantastic
it's all working now
thank you very much!!
might also apply it to the camera to see how it looks
glad it worked!
np, really glad you like it