#Edge of Radius

1 messages · Page 1 of 1 (latest)

plucky dust
#

This shoot radius, is it a circle? @fickle pike

fickle pike
plucky dust
#

Is it a circle?

#

Since you are speaking of Radius one might assume it is a circle, but since I have no idea, and for the sake of not working with false assumptions, is it?

fickle pike
#

I would like it to be a circle yes. This is the whole script for now, some stuff is not used and other is just for debugging

https://gdl.space/loyarixezo.cs

plucky dust
#

Are you 100% here now?

fickle pike
#

Im here yeah?

plucky dust
#

Great. I hit many dead ends lately, and I dont' have time to wait for people. Anyway

fickle pike
#

Ah makes sense

plucky dust
#

Does this circle exist yet in any way?

fickle pike
#

Well it only exists when checking if the hit.point is outside the maxAtkDist float

#

Else there is no gameobject or anything else

plucky dust
#

is this 2D or 3D?

fickle pike
#

3D

plucky dust
#

kk, trying to visualize
Anyway, my initial thought is the following

#

I'm just not sure it will work in 3D

fickle pike
#

I can like paint a small pic of what im trying to do to further explain

plucky dust
#

A screenshot of the scene could help

fickle pike
plucky dust
#

When the mouse button is clicked,
the raycast is performed,
and if something is hit,
then the object should be spawned at position:

fickle pike
#

Well

plucky dust
#

(I'm typing code)

fickle pike
#

ah ok

plucky dust
#
float distance = Vector3.Distance(transform.position, hit.point);
float spawnDistance = distance;
if (distance > maxAtkDist) 
{
    float overshoot = (distance - maxAtkDist)
    spawnDistance -= overshoot;
}
executeAttack()
#

need to google some Vector logic

#

code is unfinished, but you get the gist of it

#

Notice how I split up the formula inside the if-statment. That's for being able to read the logic, without understanding the full formula

fickle pike
#

Oh wait, thats what I did, but forgot to set the new position

#

Thanks :D

plucky dust
#

That's what I was about to google how to calculate

#

really hazy this Saturday xD

#

If that solves it, good stuff. Let me know once that's done, or if you need help with the last bit.

fickle pike
#

Sure, just need to clean some cloths real quick

plucky dust
#

changed the Vector3s to floats, because d'uh

fickle pike
#

Ight im back and going to try it now

#

Changin them to floats won't work though, I only care about the X and Z axis and the executeAttack function requires a vec3 to change the position of the debugOBJ

#

This is what I got with trying another way

#

This is the new script ```cs
void onPlayerAttack(InputAction.CallbackContext ctx)
{
Ray ray = cam.ScreenPointToRay(pManager.mousePos());

    if (Physics.Raycast(ray, out hit))
    {
        float distance = Vector3.Distance(transform.position, hit.point);
        if (distance > maxAtkDist)
        {
            // Get point on hit.point direction closest to sphere radius (maxAtkDist)
            float overShoot = (distance - maxAtkDist);
            Vector3 newPos = new Vector3(hit.point.x - overShoot, hit.point.y, hit.point.z - overShoot);
            executeAttack(newPos);
        }
        else
            executeAttack(hit.point);
    }
}

void executeAttack(Vector3 hitPoint)
{
    debugOBJ = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    debugOBJ.transform.position = hitPoint;
}```
#

For some reason that makes it spawn in 3 random positions

#

This is what I have been kinda thinking but I hoped there was a function in the Mathf library that could just get me the closest point to the radius

#

@plucky dust

plucky dust
#

Reading

#

newPos is wrong

fickle pike
#

what should newPos be then?

plucky dust
#

Checking that atm

Vector3 direction = destination - origin;

fickle pike
#

I knew how to get the direction, i just don't fully know how to get the right position

plucky dust
#

it's a tough google tbh

fickle pike
#

Yeah thats why i came here lol, I didn't know what to google

plucky dust
#
Vector3 origin = transform.position;
Vector3 direction = new Vector3(1,1,0);
float distance = 0.5f;
Vector3 destination = origin + (direction * distance);
#

you need to modify direction

#
Vector3 direction = destination - origin;
plucky dust
fickle pike
#

So this?

Vector3 Direction = transform.position - hit.point;
Vector3 destination = transform.position + (Direction * maxAtkDist);```
plucky dust
#

destination - origin

fickle pike
#

oh ok

plucky dust
#

it's a tricky formula ^^

#

but simple

fickle pike
#

Yeah, I guess i have mixed them this whole time them lol. Ill go for google and let you free now lol

plucky dust
#
float distance = Vector3.Distance(transform.position, hit.point);
float spawnDistance = distance;
if (distance > maxAtkDist) 
{
    float overshoot = (distance - maxAtkDist)
    spawnDistance -= overshoot;
}
executeAttack()
#
float distance = Vector3.Distance(transform.position, hit.point);
float spawnDistance = distance;
if (distance > maxAtkDist) 
{
    float overshoot = (distance - maxAtkDist)
    spawnDistance -= overshoot;
}
Vector3 direction = (hit.point - transform.position).normalized;
Vector3 destination = transform.position + (direction * spawnDistance)
executeAttack(destination)
#

I think that's final, if you can implement that in your code.

fickle pike
#

Alright Thanks so much :D

plucky dust
#

You're welcome. Good luck, and have a nice weekend 👋

fickle pike
#

Yeah you too :D

plucky dust
#

You weren't wrong about the Trigonometry part

fickle pike
plucky dust
#

I haven't actually run this code, but here is a polished version

private Vector3 NewPos(Vector3 origin, Vector3 destination, float maxDistance = 0f)
{
    float distance = Vector3.Distance(destination, origin);
    float clampedDistance = distance;

    bool maxDistanceIsRelevant = maxDistance > 0f;
    bool distanceIsHigherThanMax = distance > maxDistance;

    if (maxDistanceIsRelevant && distanceIsHigherThanMax)
    {
        float overflow = (distance - maxDistance);
        clampedDistance -= overflow;
    }

    Vector3 direction = (destination - origin).normalized;
    Vector3 clampedDestination = origin + (direction * clampedDistance);

    return clampedDestination;
}
#

@fickle pike There was one error in the solution I gave you.

// Wrong.
Vector3 direction = destination - origin;
// Correct. 
Vector3 direction = (destination - origin).normalized;
#

Corrected the last two script segments here.

fickle pike
#

Ah ok thanks, and with the answers.unity.com I haven't been able to get on the last two weeks. I have been on many different networks thees two weeks so its kinda weird if they all had problems with that one site

plucky dust
#

That's odd. Are you still not able to load the site?

fickle pike
#

nope

plucky dust
#

may I ask which country or continent you're on?

#

actually, nevermind

#

it will only lead to speculation

#

Try VPN

#

Epic Privacy Browser has 1-click VPN built in.

fickle pike
#

It should be fine in denmark

plucky dust
#

Hm. Using custom DNS or anything?

fickle pike
#

Nope all stock to keep it easy for my parents

plucky dust
#

if you're on Windows you can open cmd and type tracert learn.unity.com to see where it stops in the chain.

fickle pike
#

im on linux lol

plucky dust
#

traceroute

#

might be the equivalent

fickle pike
#

not on an arch based distro

plucky dust
#

Have you restarted your computer these past weeks?

#

is this a laptop?

fickle pike
#

I haven't used this one the past 6 weeks doe to me living on a school, its a concept really hard to explain because its not found outside denmark

#

But it also doesn't load on my laptop

#

or phonr

fickle pike
#

oh wait now its up on my phone

plucky dust
#

Folkhighschool?

#

If you've been on 4 networks with the same Arch Linux installation, perhaps there is something missing in Linux.

#

if that was the case

fickle pike
plucky dust
#

kk

fickle pike
plucky dust
#

it doesn't even leave your computer?

#

That's odd. And this is spiraling into very off-topic.
But for the sake of testing your arch build for flaws, keep a Live USB of some distro that just works with everything, so that you can quickly see if the Live version can achieve things your Arch installation cannot.

fickle pike
#

Im sure I can fix it at some point

#

anyways the code you sent was a little cleaner than what I made, but both works

#

Thanks again :D

plucky dust
fickle pike
#

you too

plucky dust
#

PS:

private Vector3 NewPos(Vector3 origin, Vector3 destination, float maxDistance = 0f)
//  = 0f
// Doesn't make sense in this context, as you'd never want to ignore that parameter. Remove.
private Vector3 NewPos(Vector3 origin, Vector3 destination, float maxDistance)
fickle pike
#

Yeah I figured lol