#eat

1 messages Β· Page 1 of 1 (latest)

rugged blaze
#

the same thing happens

wet ivy
#

That's incredibly strange

rugged blaze
#

the tleeporting

wet ivy
#

I'm using almost exactly the same code

rugged blaze
#

also i changed findObjectOf("cube)"

#

to

#

collider.gameObject

wet ivy
#

Oh yeah... sorry XD

rugged blaze
#

no its fine lol πŸ˜„

#
                {

                    GameObject currentObject = collider.gameObject;

                    Vector2 placeYouWantToGo = transform.position;
                    Vector2 pos = currentObject.GetComponent<Edible>().pos;

                    float mag = (placeYouWantToGo - pos).magnitude;
                    float speed = Time.deltaTime * 8f;
                    float stepSize = speed / (mag * mag);
                    float orbitRadius = 2f;
                    float orbitSpeed = Time.time * 10f;

                    if (2 < mag)
                    {
                        pos += stepSize * (placeYouWantToGo - pos);
                    }
                    else
                    {
                        pos += speed * (placeYouWantToGo - pos);
                    }

                    Vector2 orbit = new Vector2(Mathf.Sin(orbitSpeed), Mathf.Cos(orbitSpeed)) * orbitRadius;

                    currentObject.transform.position = pos + orbit;
                    currentObject.GetComponent<Edible>().pos = pos;

                }``` thats still my code
#

the edible is this

wet ivy
#

Pls could you write csharp after your three backticks

rugged blaze
#
using System.Collections.Generic;
using UnityEngine;

public class Edible : MonoBehaviour
{

    public Ability abilityToSet;
    public int healAmt;

    public Vector2 pos;

    void Start()
    {
        pos = gameObject.transform.position;
    }

}
```csharp
wet ivy
#

Thank you it just makes it easier to read

rugged blaze
#

how lol

wet ivy
#

Oh...

rugged blaze
#

😐

wet ivy
rugged blaze
#

right?

#

i want it to go to the game object the script is attached to

wet ivy
#

Is this script attached to the object you want your spiralling things to go towards?

#

Oh okay

wet ivy
#

```csharp

wet ivy
#

```csharp
code stuff
```

rugged blaze
#
foreach (Collider2D collider in objects)
                {

                    GameObject currentObject = collider.gameObject;

                    Vector2 placeYouWantToGo = transform.position;
                    Vector2 pos = currentObject.GetComponent<Edible>().pos;

                    float mag = (placeYouWantToGo - pos).magnitude;
                    float speed = Time.deltaTime * 8f;
                    float stepSize = speed / (mag * mag);
                    float orbitRadius = 2f;
                    float orbitSpeed = Time.time * 10f;

                    if (2 < mag)
                    {
                        pos += stepSize * (placeYouWantToGo - pos);
                    }
                    else
                    {
                        pos += speed * (placeYouWantToGo - pos);
                    }

                    Vector2 orbit = new Vector2(Mathf.Sin(orbitSpeed), Mathf.Cos(orbitSpeed)) * orbitRadius;

                    currentObject.transform.position = pos + orbit;
                    currentObject.GetComponent<Edible>().pos = pos;

                }```
#

there

#

srry

wet ivy
#

Nice thanks

#

That's so strange

rugged blaze
#

wait nvm i cant tell

rugged blaze
wet ivy
#

Can you please debug the pos aswell as the transform.position

rugged blaze
#

transform.pos of the object im eating?

wet ivy
#

Yeah

rugged blaze
#

POS: (10.7, 0.0)(11.1, 1.9, 0.0)

POS: (10.7, 0.0)(12.2, -1.3, 0.0)

POS: (10.7, 0.0)(12.1, -1.4, 0.0)

POS: (10.7, 0.0)(12.0, -1.5, 0.0)

POS: (10.7, 0.0)(11.9, -1.5, 0.0)

POS: (10.7, 0.0)(11.9, -1.6, 0.0)

POS: (10.7, 0.0)(11.8, -1.6, 0.0)

POS: (10.7, 0.0)(11.8, -1.7, 0.0)

POS: (10.7, 0.0)(11.7, -1.7, 0.0)

POS: (10.7, 0.0)(11.6, -1.8, 0.0)
wet ivy
#

Oh... XD

rugged blaze
#

?

#

i think it has to do with adding orbit to one value

#

but not the other maybe?

wet ivy
#

Oh yeah that's right

rugged blaze
#

oh

wet ivy
#

I forgot about the orbits

rugged blaze
#

wait but howcome it works for u tho?

wet ivy
#

That's pretty reasonable then

#

Wow

#

Could it be...

#

The orbit radius

#

Try set it to 0

rugged blaze
#

lol

#

it moves very slowly on the ground

#

then gets closer and slightly faster

#

then does a 360 spiln

#

and stops spinning and moves slowly onthe ground

#

but it did actually move towards me! :DDD

wet ivy
#
if (2 < mag)
        {
            pos += stepSize * (placeYouWantToGo - pos);
        }
        else
        {
            pos += mag / 2f * (placeYouWantToGo - pos);
        }
#

I think that should fix that

rugged blaze
#

what about the speed variable?

wet ivy
#

So it's teleporting because the orbit radius is too big I guess, just set it to like 0.1f or something

rugged blaze
#

okay

#

what about the speed var?

wet ivy
wet ivy
rugged blaze
wet ivy
#

We use it for stepSize

rugged blaze
#

oh

#

also i think it works

#

its just very fast

#

oh uhm

#

it works at start

#

then it like moved a lil

#

then instantly teleports to plr

wet ivy
#
if (>>>>thisvalue<<<<< < mag)
        {
            pos += stepSize * (placeYouWantToGo - pos);
        }
        else
        {
            pos += mag / 2f * (placeYouWantToGo - pos);
        }
#

Try making that value smaller

#

And also change the second equation to make it a bit smoother

#

I'll try and find a good middle ground

rugged blaze
#

wait so for thisvalue

#

should it be like

#

1

#

or like

#

0.5

#

or like

wet ivy
#

Try 0.1f

rugged blaze
#

0.001

#

okay

#

yESESES

#

also i didnt change the second equation

#

it works fine

wet ivy
#

Awesome

rugged blaze
#

your an absolute legend ommgmgmgmg yeysyeyesyssses

wet ivy
#

I'm just glad we finally made it work

rugged blaze
#

yeah

#

thank you so much omgy goghshshs

#

it workrksssrksks

wet ivy
#

So if you want it to speed up more when it gets closer

#

You want to edit the stepsize equation and the denominator where it's like (mag * mag)

rugged blaze
#

would i want (mag*mag) to be bigger to make it go faster?

#

or smaller?

wet ivy
#

Instead try Mathf.Pow(mag, someValueGreaterThan1) and tweak it till it's good

#

Well

rugged blaze
#

whats pow?

wet ivy
#

You know like 2^3 = 2 * 2 * 2

#

Pow is like ^

rugged blaze
#

oh

#

yeh

#

ik what it means i just didnt know what pow stood for

wet ivy
#

power

rugged blaze
#

i do now vtho πŸ™‚

wet ivy
#

Because 2^3 means 2 to the power of 3

rugged blaze
#

yeah

#

ik

wet ivy
#

So

#

If you increase x in Mathf.Pow(mag, x) then it will be insanely slow the further away you are but it will speed up super super quick when it's close to the object

rugged blaze
#

so

#

would this also work

#

((mag * mag) * 1.5f)

#

and would that make faster or slower?

wet ivy
#

Yeah but that's the same as just dividing the numerator by 1.5

#

That would make it go slower

#

But it wouldn't change it's acceleration at all

rugged blaze
#

okay

wet ivy
#

Of course you can always just go on desmos and write a few equations and see what you like the look of

rugged blaze
#

alright

#

Mathf.Pow(mag, 1.5f); is faster ? u said

#

and like

#

0.8f is slower?

wet ivy
#

Currently your velocity equation looks like this

rugged blaze
#

😐

wet ivy
#

If you draw what you want your speed to look like I can try and make an equation

rugged blaze
#

well ig

#

but can you explain to me how it would work?

#

lol :|||

wet ivy
#

You mean if I write the equation I explain how it works?

#

Or how the current one works

rugged blaze
#

like

#

how i would change

#

and stuff

#

also ^

wet ivy
#

Try fiddling around with that

rugged blaze
#

okay

wet ivy
#

But bare in mind

#

x is equivalent to the distance you are away so you need to think of this as the velocity of the object is when you're looking at the x axis far on the right and then it speeds up as x gets closer to 0

rugged blaze
#

yeah sooo

#

i like this number 😐

#

10000000000000000000000000000 as the numerator

#

😐

wet ivy
#

XD

rugged blaze
#

so how do i convert that into the code?

wet ivy
#

Does this look better?

rugged blaze
#

um i want it to start speeding up a little before

#

like

#

7

#

and then get faster and faster

wet ivy
#

Like that?

#

I must warn you it will be.... very very fast

rugged blaze
#

oh

#

well its okay cause i did

#

Pow(mag, 0.85) and it jworks pretty good

wet ivy
#

Oh

#

That doesn't accelerate though

rugged blaze
#

😐

wet ivy
#

XD

rugged blaze
#

uh

wet ivy
#

If you say it works good then it works good right?

rugged blaze
#

idk

#

ill prob leave it at 1

wet ivy
#

And leaving it at 1 will make it move at a constant speed

rugged blaze
#

oh

#

1.2?

wet ivy
#

That will accelerate it yeah

rugged blaze
#

whatevs ill just fiddle you dont have to worry

wet ivy
#

Alright but if you want to try this

#

It's good because the velocity doesn't go to infinity

rugged blaze
#

would that be

#

1 / (e*(x-7))

wet ivy
#

1/(mag * Mathf.Exp(mag - 7))

#

That should work in code

rugged blaze
#

okay

#

so how do i now (in the future) how to convert e and x and etc

wet ivy
#

Hmmm there won't be much point in converting e

rugged blaze
#

well

#

e is

wet ivy
#

But if you mean in the future if you want a new equation

rugged blaze
#

2.71828 but yeah

wet ivy
#

All you have to do is use mag as your x and make sure you multiply your equation by 1/mag

rugged blaze
wet ivy
rugged blaze
#

uhh

#

speed / (1/(mag * Mathf.Exp(mag - 7))) just makes it orbit where it is

#

but not come to the person

wet ivy
#

Oh no

rugged blaze
#

?

wet ivy
#

speed/(mag * Mathf.Exp(mag - 7))

rugged blaze
#

oh

wet ivy
#

Honestly, just get rid of speed and put whatever number you want there

rugged blaze
#

xD i put 1 and it tp directly behind me

wet ivy
#

Yes it will be very fast lmao

#

Oh and if it's way too slow when it's far away just add a constant to it

#

So you should end up with the equation

#

a/(mag * Mathf.Exp(b * mag - c)) + d

#

And changing all these variables to manipulate your velocity curve

#

And then the other variables like orbit radius and orbit speed should be pretty self explanatory πŸ˜„

rugged blaze
#

well

#

the a

#

i change and it tp super far away

#

or right behind me

#

the speed/(mag*mag) works better :||\

wet ivy
#

Hey do what you want

rugged blaze
#

nvm

#

c was to big

wet ivy
#

Whatever looks good

rugged blaze
#

eyah well

#

im just happy we got to work lol

wet ivy
#

$\frac{0.002}{e^{\left(3x-7\right)}}+0.3$

#

Hmmm

#

0.002f/(mag * Mathf.Exp(3 * mag - 7)) + 0.3f

rugged blaze
#

6 / (mag * Mathf.Exp(mag - 1)) does work tho

#

very good infact

wet ivy
#

It works terribly for me XD

#

But good

#

Whatever it doesn't matter what equation you use

rugged blaze
#

its cause the 7 was way to big

wet ivy
#

You've got a spiralling edible now

rugged blaze
#

yes πŸ™‚

wet ivy
#

Good luck with the rest of your game πŸ˜„

rugged blaze
#

thankyou :DDD

rugged blaze
#

its because on speed

#

my 6 was the speed var instead

#

and the speed var still had

#
  • time.deltatime
wet ivy
#

Ohhhh yeah

#

Without delta time it will be very fast

#

Another option is to use a bezier curve

#

Which you can control very easily