Tag Info

Hot answers tagged

3

Calculate the dot product to determine how close two vectors are. The dot product is 1 when they are exactly the same, -1 when they are exactly opposite, 0 when they are perpendicular, and decimal values when partway. So take the current direction, the target direction, then Vector3.Dot() and check if greater than .9 (or whatever threshold you decide looks ...


2

jhocking's answer about dot product is the right answer to the question, but if you are rotating your object over time to face the right direction, inside that function you must be calculating how much you have left to rotate so that you know what direction to rotate and so that you don't rotate too far and overshoot. That means that inside that function, ...


2

First, it won't solve your problem, but there are a few general problems with your code. The conditions for your if branch will always be true if transform.localEulerAngles.x >= 0 and <= 360. The > 270 part is redundant since if x is less than 270, it is still possible to be >= 0. If x is 0 and lookAxisX is > 0, then adding -lookAxisX will make x < ...


2

Something like this: transform.position = player.transform.position - player.transform.forward * distance; transform.LookAt(player.transform); where float distance is the distance of camera form player Consider also the solution 2 : Make camera child of player and in your player die script , you can "deatach" camera from player object transform.parent ...


1

I personally never calculate an angle like that. I like to work with vectors, it might be slightly less efficient but this way you can do it step by step, it gets more readable and easier to understand. So what is a vector? A vector is essentially a direction and a magnitude together. Often in games it is used as a position data structure too but ...


1

You can always try to use the clamp method: Ref: http://docs.unity3d.com/ScriptReference/Mathf.Clamp.html Example transform.localEulerAngles = new Vector3(Mathf.Clamp(transform.localEulerAngles.x, 0f, 90f), 0, 0); **This is just a push in the right direction (above is untested)


1

Exerpt from the 3D CSG module I wrote for my engine. You should be able to derive from this easily enough. SOLID_C *Rotate(const V3 &axis,const T angle) { T a=radians(angle),c=cos(a),s=sin(a); V3 rt[3],m[3],mt[3],ax=((V3)axis).normalise(),t=ax*(1.-c); rt[0][0]=c+t[0]*ax[0]; rt[0][1]=0+t[0]*ax[1]+s*ax[2]; rt[0][2]=0+t[0]*ax[2]-s*ax[1]; ...


1

Let's test them! First implementation Rotate vec2(0,100) by 0 degrees -> vec2(0,100) looks good! Rotate vec2(0,100) by 90 degrees -> vec2(100,0) looks good! Rotate vec2(100,0) by 0 degrees -> vec2(0,100) uh-oh! Rotate vec2(45,45) by 0 degrees -> vec2(0,100) uh-oh! Rotate vec2(-3,angry warthog) by 0 degrees -> vec2(0,100) uh-oh! So there is clearly a ...


1

Since you are working in 3d world space, why not use the BoundingFrustum class? BoundingFrustum cameraBounds = new BoundingFrustum(view * projection); if(cameraBounds.contains(location)) { // it is in view } else { // not in view } edit. I assumed you are using XNA. If not, you can still reflect the XNA code to see how to make a Bounding frustum ...


1

Correct me if I am wrong, but from what I understand, you want to achieve the following: If so, this can be achieved using trigonometry: float easing = 0.075f; float direction = Math.atan2(target.y - sprite.y, target.x - sprite.x) / Math.PI * 180; if (direction < sprite.rotation - 180) { direction += 360; } if (direction > sprite.rotation + ...


1

I think the issue is that the input is being polled every frame as part of the Update(). I would suggest pulling the input from the Update() and using input callbacks instead. That way the input is only polled when fired, and not every frame. That should cause the direction to only update with input changes, and the Update() will continue to render the same ...



Only top voted, non community-wiki answers of a minimum length are eligible