Jump to content

  • Log In with Google      Sign In   
  • Create Account

PiCroft

Member Since 12 May 2007
Offline Last Active Dec 06 2013 04:14 AM

Topics I've Started

Flying physics: acceleration while diving/ascending

08 February 2012 - 07:45 AM

Hi,

I've got a small prototype involving a character that flies across a 2d landscape. The character in question isn't a plane and I'm not requiring any advanced physics such as lift, gravity etc.

The character in question currently moves by having a set speed and between frames, I calculate the angle I need to turn from the default and set the character's heading appropriately by rotating the movement vector. While this works, the character has a very uniform movement style and speed that isn't very interesting.

Due to the way I've designed it so far, I'm having trouble creating a system where the character accelerates/decelerates in a fluid way that isn't either horrible to look at or a nightmare to code and I was wondering if anyone might suggest a nice method/way of thinking about the problem that might work?

Please let me know if I need to clarify anything.

Screen space to local - "denormalizing"

23 December 2011 - 04:54 AM

Hi there.

I have a simple game where I want to be able to drag tiles around on a board. The game is entirely 2D.

I have it set up so that it takes in a touch (or mouse click), sees if the click is with the boundary of a tile and then moves it accordingly.

However, the engine I use doesn't provide localised touch coordinates, only in screen coords. This means that if I click in the centre of the screen, instead of getting 0,0, I will get half the window size in length/height in pixels. Now, I expect this for screen coordinates, but what I don't know is how to convert this to local coordinates.

I have made a start by normalising the coords and shifting them so they are relative to the centre of the screen:

float width = zGetScreenWidth();
	float height = zGetScreenHeight();
	float halfwidth = width/2;
	float halfheight = height/2;
	float aspect = 1.3333f;

	float x = touch_coords.x;
	float y = touch_coords.y;
	
	float dx = (x/halfwidth-1.0f)/aspect;
	float dy = 1.0f-y/halfheight;

	return newpos;

This works, when I click dead-centre in the middle of the screen I do indeed get 0,0 but because it is normalized, all my coords are clamped between 1 > -1. I'm not sure how to "up-scale" the coordinates so they match the local coordinates of my game board. Can anyone assist?

"Dipping" physics: flying object swooping and then returning to previous height

27 October 2011 - 09:16 AM

Hello,

I'm trying to create a simple 2D game where an object is flying at a particular height at constant velocity. When I press a button, the object starts to dive, the dive getting steeper the longer you hold the button. When you release the button, the object levels out, then starts to climb back up to its original height.

Could someone give me some math pointers for making this mechanic?

stl:list iterator error: list iterators incompatible

26 October 2011 - 09:13 AM

I've got code which loops through a list using an iterator. It performs a check on that object and if the condition fails, the item is deleted using the list::erase() method.

std::list<cHBGameObject*>::iterator i;

	//remove any object that has passed the cutoff
	if(!lObjects.empty())
	{
		i = lObjects.begin();

		while (i != lObjects.end())
		{
			if((*i)->checkIfOverDeletionThreshold(xDeletionPoint))
				lObjects.erase(i);
			else
				++i;
		}

	}

In this case, the crash occurs if there is only 1 remaining object and the object is deleted, then when it returns to the "while" statement, the error is thrown.

I can sort of see where I'm going wrong, I think when it hits "while", because the list is empty, it may be that the iterator no longer points to anything valid. I have looked up examples to make sure I'm not doing it wrong but every analogous example I have seen have suggested this approach to looping through a list where you may delete objects. Besides, being able to delete objects in this manner is one of lists' advantages over vectors, no?

Could someone kindly point out where I am going wrong?

Converting map coords to screen coords

19 October 2011 - 02:57 AM

I've got a problem where I'm trying to get a character on screen in a top-down 2d game who always faces the mouse cursor. The engine I'm using uses a map, and all objects on the map provide their position relative to the map origin. I can use calls to get the mouse position in screen coordinates and I have a camera thats always centred in the middle of the screen.

I've currently got it working by getting the mouse coords (in screen space), getting the camera (which is provided in map coords for some reason, but since its always centered, I can just set it to half screen height/half screen width) and calculating the delta as (mouse pos - cam pos) and getting the angle from there.

The problem is, the game is designed with a drifting camera that floats slightly ahead of the player as they move forwards to allow them to see further ahead, and since the character turning angle is calculated from the centre of the screen, the character aim is off when the camera drifts ahead, since the character is no longer at the centre of the screen.

What I'm looking for is a way to convert the character in map coords into screen coords, so I can perform the calculation from there.

Any help would be appreciated!

Also, any questions, feel free to ask if I haven't explained something well.

PARTNERS