#teleport

1 messages · Page 1 of 1 (latest)

marble violet
latent iris
#

Oh this is cool

marble violet
#

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?

latent iris
#

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

marble violet
#

are you just instantaneously adding a high force to make it teleport?

latent iris
#

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

marble violet
#

well it seems like you're going to have to calculate every frame the direction to apply the 'gravity', right?

latent iris
#

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

marble violet
#

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?

latent iris
#

do you mean blue as the gravity?

marble violet
#

yeah

latent iris
#

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

marble violet
#

ok so why would we fall off to the right?

latent iris
# latent iris

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)

marble violet
#

that seems like something that would happen in real life

latent iris
#

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

latent iris
marble violet
#

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

latent iris
#

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

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

latent iris
#

and do you know the difference between rb.transform.position and the normal version?

marble violet
#

I don't, also not super experienced with rigidbodies. Probably find some stuff on google though

latent iris
#

Okay thanks, have a good one!

normal sparrow
#

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.

latent iris
#

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

normal sparrow
#

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

latent iris
#

I actually will be having a gravitational force that always pushes downwards

normal sparrow
#

then just combine the two vectors

#

i.e. custom physics, but not really, cause you only change gravity

latent iris
#

Following the surface normal sounds good

normal sparrow
#

you could fix your acceleration problem by just overwriting velocity while in contact

latent iris
#

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

latent iris
#

Would I be better off not using rb.AddForce?

normal sparrow
#

Depends on the rest of your design/needs

#

Have to leave now too, sorry