Tag Info

New answers tagged

0

I can't help you exactly with code because I'm not sure where all your variables are coming from. If you provide some context to this code, I can help more specifically. In the meantime, take a look at this picture: If you know how far you want the sprite to travel, and you know the angle. You can calculate the x and y distances using the formulas from ...


0

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 < ...


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)


0

If you can obtain the Up, Front and Right vector, you have a full orthonormal basis to reconstruct the quaternion, you don't need to worry about Euler angles, just forget the Euler angles and build the quaternion directly from the Orthonormal Basis (x axis = -Right, y axis = Up, z axis = Front). The simplest way to do this is to build a rotation matrix from ...


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, ...


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 ...


0

You can use Quaternion.LookAt() always and then just move your object forward whenever you want.


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]; ...


0

I have solved the problem. //Roation around the Origin //Individual matrices #include "graphics.h" #include "Vector2d.h" #include "Coordinates2d.h" #include "Polygon2d.h" #include <math.h> #include <iostream> #define PI 3.141 #define DEG 45.00f #define RAD 6.283185308 / (360.0 / DEG) int main() { //////////////////////////////////////// ...


-2

Most of trigonometric functions take radians as input, this may be your issue. So your theta should be float theta = angleInDegrees*PI/180


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 + ...


0

This seems like a real nice fit for using something like bias and gain. Using those functions, you do a simple linear interpolation, but before using your "percent" value in the lerp, you pass it through a function to make the percent value non linear. This makes it so it still takes the same amount of time to do, but you can make it faster in the ...


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 ...


0

Using a rendertarget may be a solution if you only have that one sprite. If your game requires a lot of those rotated, scaled sprites, you might want to look into a pixelshader. You might calculate the occurence of a color within your intended pixel size (your spritepixels may be 3x3 screen pixels) and color the resulting screen pixels accordingly.


-1

Note that above fails for r1=720 and r2<=0. I would like this... d = mod (r1 - r2), 360) if(d >= 180) //r1 > r2 d = d-360; else if(d < -180) //r1 < r2 d = d+360;


0

Try adding an if statement saying if neither of the axis are equal to zero then change the rotation, this would eliminate facing forwards when there is 0 on each axis. if(direction != Vector3.zero) {Quaternion rotation = Quaternion.LookRotation(direction, Vector3.up); transform.rotation = rotation; } Hope this helped. Here is another solution on ...


1

I think you might be overcomplicating things - why not just set the "origin" of the hook to new Vector2(0, hookTexture.Height / 2) If you simply draw it like this: spriteBatch.Draw(hookTexture, position, null, Color.White, rotation, new Vector2(0, hookTexture.Height / 2), 1.0f, SpriteEffects.None, 0.0f); That way the hook is drawn and rotated around ...


4

Rotations are extremely order-dependent. Doubly so when you're composing rotations in local space (so the axes you're rotating around are themselves rotating from one frame to the next) As an extreme example, imagine that you start facing z+, and in one frame you pitch (x rotation) 90 degrees up. In the next frame, you yaw (y rotation) 90 degrees left. ...


0

Only change the rotation whenever your distance is above a certain delta. Also center your sprite, right now you're using the top-left corner of the sprite.



Top 50 recent answers are included