New answers tagged

2

This is a strange behaviour in Unity's scale inheritance system. If the parent has a non-uniform scale, when you rotate the child, they deform/stretch like a rubber band. Try adding an empty child GameObject to Player GameObject and parent the Camera GameObject to empty one, and put the rotation script on Camera. This makes parent of the Camera a ...


0

You can simply do GetComponent<SpriteRenderer>().flipX = true;


0

Vector normalization is mostly used when you want the vector to have a length of 1. Another use is if you want the vector to have a specific length then you would normalize the vector which guarantees the vector has a length of 1 and then multiply by the number you want it's length to be.


0

That's more or less how I would do it too. One thing you can try is to have the ground pieces contain a normal vector that you can quickly query to align the bike to the slope.


0

The simplest way to do this is to use a hermite spline and lerp the parametric value.


0

Why not lerp the position and update the target destination as it changes? You might have to look at how lerping works but it would look something like this: public position startMarker; public float duration = 5.0f; private float startTime; void Launch() { startTime = Time.time; } void Update() { float distCovered = (Time.time - startTime) / ...


10

The edit is reassuring. :) Okay, here's a straightforward update loop... Assuming when we fire the missile we initialize remainingFlightTime = 5f then... void UpdateMissile(float deltaTime) { remainingFlightTime -= deltaTime; // At the end of the trajectory, snap to target & explode. // The math will put us there anyway, but this saves // ...


0

one good way of doing it, is creating a new gameObject where you want the anchor to be, and every frame checking if the player is farther than 1 unit from the anchor. When you want the anchor to stop it's effect, just create a script constantly moving the anchor to the player.


1

You can accomplish this by using linear interpolation. https://msdn.microsoft.com/en-us/library/bb197807.aspx float speed = 0.1f; //value between 0 - 1 Position = Vector2.Lerp(Position, DesiredPosition, speed); Another way to do it is to incorporate a time value, while keeping track of the start and end positions. This ensures the movement will be the ...


0

Welcome to XNA! First off, I'l strongly advise you to switch to Monogame. It uses the same bindings as XNA and your workflow will not change much. Plus it is under active maintenance. Also, before you rush into making a game you should check out some tutorials on sprite animation and frame independent movement. On to your question then. I've posted the ...


1

This is the while loop above redone. Kind of ugly and repetitive but it works. I had to use Math.floor and Math.ceil to solve the collision issues which is due to precision I guess. Any spare dt left over if the action sequence is finished is discarded so that might be something to save for accuracy but the timesteps are really small so it may not be ...


1

Math.cos uses radians, not degrees. You want to go from 0 to 2* Math.PI You could do that like this: if (Keyboard.isKeyDown(Keyboard.KEY_D)) { if (i < 360) { //Convert to radians by multiplying by Math.PI*2f/360f float theta = Math.PI * 2f * (float) i / 360f; setX((float) (groundState.getX() + groundState.getRadius() * ...


0

The problem was in this line. TextureRegion tmp = new TextureRegion(Asset.sprites, SPRITE_SIZE * SPRITE_COUNT, rand * SPRITE_SIZE); I've used the wrong params, so I forgot width and height. I changed to this. TextureRegion tmp = new TextureRegion(Asset.sprites, 0, rand * SPRITE_SIZE, SPRITE_SIZE*SPRITE_COUNT, SPRITE_SIZE);


0

In Ye olden days we used to use the bottom 16 bits of a long as the fraction part. struct HiLo { public: unsigned short m_lo; unsigned short m_hi; }; union LongFraction { public: LongFraction() { m_all = 0; } HiLo m_hilo; unsigned long m_all; }; Then 0-65535 becomes the fraction part. LongFraction pos; pos.m_all += ...


2

One way to do this is to only run physics and render code when the event queue is empty: ALLEGRO_EVENT_QUEUE* e = al_create_event_queue(); al_register_event_source(e, al_get_keyboard_event_source()); al_register_event_source(e, al_get_mouse_event_source()); al_register_event_source(e, al_get_joystick_event_source()); al_register_event_source(e, ...


3

If you use al_wait_for_event, then you need to use a ALLEGRO_TIMER as well to generate pulses (every 1/60th of a second for example) and you update your movement every pulse. That way there is always an event happening on Allegro. If you still don't want to use a timer, you can use al_wait_for_event_until and then specify till when you wait for an event for ...



Top 50 recent answers are included