Jump to content
Sign in to follow this  
MadMax50

nested if statements

Recommended Posts

hello,

I am trying to get a nested if statement to work properly in sops.

First I have my constraints being deleted by the Y value

then if the Y value is less than a certain value , I want to set @strength=-1 based on a random condition. 

Then i want to delete all the constraints that are not @strength=-1

The result should just be  only the constraints that are @strength=-1  if it is below a certain @P.y value. 

I am not sure what I am doing wrong here...

float myRand= rand(@primnum*234.234);

f@strength=100;

if(@P.y<chf("Thresh_Y")){
    if(myRand>chf("Thresh")){
        f@strength=-1;
            if(f@strength>0){
                removeprim(0,@primnum,0);
        }
   }
   
}

 

I will also attach my scene file for anyone that wants to take a look

Thank you. 

nested_if_statements.hipnc

Share this post


Link to post
Share on other sites

If I understood you correctly this is what you want, I put color instead of deleting so you can see what is happening. Add the removeprim function where @Cd is or put a blast at the end "@strength==-1" and check delete non selected.

 

float myRand= rand(@primnum*234.234);

f@strength=100;

if(@P.y<chf("Thresh_Y")){
    f@strength=-1;
    @Cd = {1,0,0};
    } else if (myRand>chf("Thresh")) {    
        f@strength=-1;
        @Cd = {0,1,0};
}

 

 

 

 

Share this post


Link to post
Share on other sites

@SepuThank you. I am trying to keep f@strength=-1 and delete everything else when it gets below a certain Y value. 

Basically i am trying to achieve an rbd sim that breaks below a certain Y value but some pieces stay together.  

I'll attach my scene with the simple rbd sim to show you what I mean.

I implemented your method into it but I am not sure how I will achieve this without another if statement in there. 

Thank you.

nested_rbd.hipnc

Share this post


Link to post
Share on other sites

this: float myRand= rand(@primnum*234.234);

is generating your random number based on @primnum, but since you are deleting constraints it will change each time so it will not be stable

create prim attrib on constraints before the sim, like: i@primid = @primnum;

then in your code use: float myRand= rand(i@primid*234.234);

Share this post


Link to post
Share on other sites

@animThank you anim. That makes sense, but unfortunately it still isn't doing what is expected. i have both methods in there using @primid as you said. Maybe you can take a look... 

appreciate the help

 

nested_rbd2.hipnc

Share this post


Link to post
Share on other sites

you are updating positions of your constraints, I get that it's cause you want to detect the P.y, but you can't leave them like that

the constraint have to stay at rest, so just use it to create your attributes for deleting, then transfer those to original constraints and delete

depending on what you are doing you may be able to use clustering instead of having to alter stuff in DOPs, but I guess this is just a proof of concept for more complex behaviors

nested_rbd2_fix.hipnc

Share this post


Link to post
Share on other sites

@anim This works great ! I never would have guessed to put an attribute copy to the rest constraints. I have a much better understanding of how the sop solver works now in dops.

Thank you !!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×