#How do I use transform scale in Visual scripting?

1 messages · Page 1 of 1 (latest)

mellow fable
#

I want the player to be able to shrink a sphere while they are staying on it and have it reset on trigger leave. How can I accomplish this?

#

Right now it looks something like this but isn't working how I thought it would

fallen fossil
#

Timer I think

#

I don't do it that way, but in your position it'd be a good go to

mellow fable
#

So this is supposed to work?

fallen fossil
#

you wanna gate these with a bool

#

hangon, you have a few options

mellow fable
#

Is onTriggerStay updating every frame?

fallen fossil
#

no, but Timer makes its own little routine

#

ive never used this node, but i think this is how it works

peak ocean
#

Dont use local scale unless its a child of a parent object

fallen fossil
#

yeah, wont suggest copying my graph, but the pieces are there

fallen fossil
#

but tbh i would use animation to do this, unless your brief specifically says you have to transform with code

mellow fable
#

So wait what am I supposed to use then

fallen fossil
#

well the key takeaway above is how the timer node works

#

do whatever you want with it though

#

in that example it goes for 1 sec

#

and you can use the % as 0 to 1 value for your lerp

mellow fable
#

Oh I see

fallen fossil
#

i cant say for sure what you will plug it into

#

but yeah I would use animation for this, and set boolean on the animator

peak ocean
#

Use remaining % because that goes from 1 to 0.

Multiply that with get scale and that shrinks object to 0.

fallen fossil
#

See if this video inspires a solution for you

https://www.youtube.com/watch?v=tveRasxUabo

In this Unity 2021 beginner tutorial I show how to setup an animator controller for a simple model we created with Blender that has skeletal animations. I add two triggers to activate the states for the animation (open and close) and then I write a C# script that uses the attached Animator controller to play the animations when the Keys O or C a...

▶ Play video
peak ocean
mellow fable
#

Something like this?

peak ocean
#

Animation is like the easiest and has more control over that behavior. But if you need to do it via coding well here's one way

peak ocean
mellow fable
#

Oh

fallen fossil
#

I'll wait till you get success with this before elaborating slightly on the anim approach, cos for your paper it is probably better to learn the code approach anyway

mellow fable
#

I only see set Local Scale

#

Not anything else that I can see...

fallen fossil
#

no lossy scale?

mellow fable
#

Oh is that what I need?

#

I see that but didn't think it was that

fallen fossil
#

wow i also cant see SetLossyScale

mellow fable
#

oh its only getLossyScale

fallen fossil
#

you do run into that on occasion with UVS, it has most things but not all things

mellow fable
#

So are there any alternative scales to use?

fallen fossil
#

local is probably fine, just be aware it will be relative to its parent

#

if it has no parent it will just use global/lossy

mellow fable
#

Oh I don't think it has one

peak ocean
fallen fossil
#

yeah, can confirm, in this case UVS just has no setter for lossy

mellow fable
#

I think I'm missing something here

fallen fossil
#

one thing might be strange there

#

its always multiplying by its current scale

#

you probably want a fixed max scale value to multiply by instead

mellow fable
#

wdym?

#

Like static float/int for value instead of getLocalScale?

fallen fossil
#

run the numbers for a moment, 90% of 1 is .9, 80% of 1 is .8, etc etc

mellow fable
#

Yea nothing is happening when I touch the sphere

fallen fossil
#

but 90% of current scale would be... .9, and then on the next frame it will be 80%, but not 80% of initial scale, 80% of current scale, which will actually be 80% of .9, this will cause a sortof exponential effect

mellow fable
#

This is what I did btw

fallen fossil
#

and you confirm your sphere is set to trigger? and that 1 of the 2 colliders has a non kinematic rigidbody?

mellow fable
#

For sphere:

#

Lemme check player tho

#

What does Player need for triggers to work?

fallen fossil
#

physX is good but with game physics we have to always assume a margin of error

#

it's possibly that because there are 2 colliders with identical radius, overlap never happens

#

the first collider there might be blocking you from overlapping with the trigger

mellow fable
#

Thats a good point but nothing really changed once I fixed it

#

0.6 radius for trigger collider

fallen fossil
#

cant say for sure though, you will generally find consistent tests wont yield consistent results with physics lol

#

this is partly because of framerate etc

mellow fable
#

Oof

fallen fossil
#

but yeah it should work what you have

mellow fable
#

What about player

fallen fossil
#

does player have a rigidbody?

mellow fable
#

Maybe something wrong with it?

#

Good question actually lol, I'm using firstPersonStarter for this assignment because that was what was instructed

fallen fossil
#

i cant remember but i used to use a downloaded asset for teaching classes and it came with a CharacterController version, as well as a Rigidbody version

mellow fable
fallen fossil
#

iirc there is some additional steps to take if you are using CC

mellow fable
#

Oh I think I am

fallen fossil
#

Ah, CharacterController

#

They've actually changed their docs since last I saw

#

it used to explicitly say one of the 2 colliders has to be a non-kinematic rigidbody, now it just "implies it" lol

mellow fable
#

It's not saying if its possible to make it trigger but the docs says there are messages associated wtih Character Controller 🙃

fallen fossil
#

you need OnControllerColliderHit apparently

mellow fable
#

Really?

fallen fossil
mellow fable
#

So is it like an event or something else?

#

Gotcha

fallen fossil
#

i haven't used CC for years lol, someone else might better guide there

mellow fable
#

Imma just try replcing the event and see what happens

fallen fossil
#

how on earth do ppl get enter/exit events from this though?

mellow fable
#

So this didn't in fact work

fallen fossil
#

Hopefully someone else can weigh in here, it's been too long since I last touched CC

mellow fable
#

Honestly I might just reuse the code from the moving platform and use it for shrinking instead, I'll just take whatever grade atp 🙏

fallen fossil
#

Trust Google AI at your discretion lol

mellow fable
#

With what isTrigger property 😭 It doens't even exist

fallen fossil
#

it might mean for the collider attached to the same object as charactercontroller

#

or it is AI and it means nothing at all lol

fallen fossil
#

i abandoned CC years ago because working with these exact things is really tedious

#

Rigidbody has its own problems of course, but generally I prefer solving those than CC's problems

mellow fable
#

Yea its really starting to show

#

Honestly at this point I might just reuse the other code and repurpose for scale, thank you so much for your help otherwise ❤️

fallen fossil
#

for sure, hopefully someone else can shed light on the CC approach too in the meantime

#

try just dropping a kinematic rigidbody on your character controller lol

#

i dont think you have to add a collider to character, the characterController itself is already one

peak ocean
peak ocean
peak ocean
#

able to shrink a sphere while they are staying on it and have it reset on trigger leave.

OH! didnt read this... I'll make a graph tomorrow when im on my computer and show you how it can be done. 2x ways: via visual script and via animation (that also goes into uVS)

Sorry - i dont work on sundays 😛

mighty birch
# mellow fable So this didn't in fact work

Is this one the Character? because i imagine you need on controller collider hit would need to be on the GameObject with the character controller. I have not used Character controller but just seems like that

#

Then you could use a custom event on the Sphere to tell it to shrink but I imagine that you still have no way of checking on exit

peak ocean
# fallen fossil no, but Timer makes its own little routine

Timer and cooldown are my favorites. I'll soon show how this can be done.

@mellow fable would help if you an illustration because "player to be able to shrink a sphere while they are staying on it"

That means..

  1. player is close?

  2. Player steps on it?

So a quick draw helps

peak ocean