#teleport
1 messages · Page 1 of 1 (latest)
Oh this is cool
What if you had a trigger collider inside of objects, so if you manage to teleport inside of one, it calls OnTriggerEnter?
I'm not even sure what happens when you teleport to halfway inside and outside of the object. Does it just push you in one direction?
I haven't gone to do it yet, from my experience rb.transform.position is usually never accurate, whereas transfrom.position is so raw it doesn't really work with the collisions
Actually i'll show you what I am actually wanting one moment
are you just instantaneously adding a high force to make it teleport?
hahaha kind of at the moment
so this is me character
it's moving at that speed, to keep it on the block I am currently adding this force
The problem is when the object moves forward
well it hits the edge and gains speed
well it seems like you're going to have to calculate every frame the direction to apply the 'gravity', right?
I have been doing that but somehow it always has a catch
if the blue speed is too weak, my character falls off the wall
if it's too strong it has the gaining speed issue, which eventually falls off anyway
I'm confused, it doesn't seem like the direction of the gravity changes as your position relative to the circle changes
you're saying it does?
do you mean blue as the gravity?
yeah
ah I just made this
so this is how I was doing it
I have a circle cast
(that has a while loop that shrinks it to get the closes point)
(pretty inefficient but idk what else to do for the precision)
then it finds that direction, and applies the force in that direction
This has been gaining speed still though
ok so why would we fall off to the right?
haha from how I code it, who knows, but it seems to possibly be delayed, where it adds speed this way
and when it gets too fast, and the gravity is too weak, it slowly pulls away and shoots off
Now I have tried doing this instead (diagram coming)
that seems like something that would happen in real life
where I see where I WILL be, then apply that blue gravity to my current position, assming that it will be applied next frame as I move
but this slows it down weirdly, and somhow speeds it up on these angles
It kinda does yeah, my goal is to have it stick to the object and keep the exact same momentum the whole way through
I'm sorry but it seems like you have a pretty complicated issue, and I have to go. Sorry about that and best of luck
all good
Thanks for checking in
I don't get why it works how it doo
Oh right, my main question was, how could I apply that blue gravity to the object without it actually adding to the velocity? eg teleport it onto the wall each frame?
if you have time to answer later, thank you anyway @marble violet
I'm not too familiar with physics in unity. But if you just set the position of the object outright I don't think that would impact the velocity. So if you do some calculation on the closest possible position for the object and just set transform.position = that
and do you know the difference between rb.transform.position and the normal version?
I don't, also not super experienced with rigidbodies. Probably find some stuff on google though
Okay thanks, have a good one!
why don't you just disable physics on contact and do movement kinematically? or do it kinematically alltogether? Seems like you don't want realistic behaviour anyway.
I have tried to disable everything apart from not going through walls
I want it to be semi realistic until I start sticking on walls
you can't have physics "half on"... but you can have collision info without it affecting motion
usually with a collision you get a contact point with a normal and a separation distance that you can use to find out where in the object your other object is and how to separate the two most quickly... that info will however be quite useless to you
so you probably want to switch to either a local gravity vector to the center point on contact if your other-object is spherical or follow the surface normal (with some smoothing) while in close proximity to an object... both can be done with physics-on by changing the gravity direction
I actually will be having a gravitational force that always pushes downwards
then just combine the two vectors
i.e. custom physics, but not really, cause you only change gravity
Following the surface normal sounds good
you could fix your acceleration problem by just overwriting velocity while in contact
I have been applying movement like this, which I know is dodgy but It's been hard to find what feel I am wanting.
//Reset Speeds
hSpeed = rb.velocity.x;
vSpeed = rb.velocity.y;
HorizontalMovement();
DoGravity();
Jumping();
DoWind();
DoCollisions();
//RoofStick();
//Convert movement to then Apply movement
hSpeedConvert = hSpeed - rb.velocity.x;
vSpeedConvert = vSpeed - rb.velocity.y;
speedConversion = 1 / Time.fixedDeltaTime; //Converts the fixed TimeStep to output FPS equivelant (Says how many fixed updates per second instead of how long until next fixed update)
//Just a line for looks (Next position of hSpeed and vSpeed)
Debug.DrawRay(transform.position, new Vector3(hSpeed * Time.fixedDeltaTime,vSpeed * Time.fixedDeltaTime,0),Color.red);
//Apply movement
rb.AddForce(new Vector2(hSpeedConvert * speedConversion, vSpeedConvert * speedConversion));
This is all in fixed update
Also thank you a lot so far, your advice really helps
How exactly would I do this, or will I need to change the way I currently do my movement updates shown above?
Would I be better off not using rb.AddForce?