unity3d - Moving something rotated on a custom pivot Unity -


i've created arm custom pivot in unity supposed point wherever mouse pointing, regardless of orientation of player. now, arm looks weird when pointed side opposite 1 drawn at, use spriterenderer.flipy = true flip sprite , make normal. have weapon @ end of arm, fine well. problem have "firepoint" @ end of barrel of weapon, , when sprite gets flipped position of doesn't change, affects particles , shooting position. essentially, has happen y position of firepoint needs become negative, unity seems think want position change global, whereas want local can work whatever rotation arm at. i've attempted this:

if (rotz > 40 || rotz < -40) {     rend.flipy = true;     firepoint.position = new vector3(firepoint.position.x, firepoint.position.y * -1, firepoint.position.z); } else {     rend.flipy = false;     firepoint.position = new vector3(firepoint.position.x, firepoint.position.y * -1, firepoint.position.z); } 

but works on global basis rather local 1 need. appreciated, , hope i've provided enough information reach conclusive result. please notify me should need more. thank in advance, , have nice day!

you can use rotatearound() desired behaviour instead of flipping stuff around. here sample code:

public class exampleclass : monobehaviour  {     public transform pivottransform; // need assign in inspector     void update()      {         transform.rotatearound(pivottransform.position, vector3.up, 20 * time.deltatime);     } } 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -