c# - How can I make this object relative to the players position? -
the player in game can levitate objects , move them around on world xy mouse. how can make levitating object move player when moves?
private void levitateobject() { //debug.log("levitating"); float yaxis = input.getaxis("mouse y"); float xaxis = input.getaxis("mouse x"); vector3 frontforce = playercamera.transform.transformdirection(vector3.forward) * (yaxis * 1.5f) ; vector3 rightforce = playercamera.transform.transformdirection(vector3.right) * (xaxis * 1.5f); vector3 currpos = levitatingobject.transform.position; vector3 nextpos = new vector3 ( levitatingobject.transform.position, elevation, levitatingobject.transform.position) + rightforce + frontforce; levitatingobject.getcomponent < rigidbody > ().velocity = (nextpos - currpos) * 10; }
i want below, object doesnt move @ all.
vector3 nextpos = new vector3 ( transform.position.x + (levitatingobject.transform.position.x -transform.position.x) , elevation, transform.position.z + (levitatingobject.transform.position.z -transform.position.z));
make player parent of object.
obj.transform.parent = player.gameobject;
then object's position relative player's positio. when player moves, object.
Comments
Post a Comment