Texture/animation gets hidden when doing SetSpeed

edited May 2012 in Help request
Hullo :)

I seem to have a problem.

I'm using orxObject_SetSpeed to move my critters about.

This works well enough.

Now, I've added to use another SetSpeed when too close to each other (e.g. bouncing)

Weirdly, when bouncing, and only then, they tend to disappear.



As you may see, they're not deleted; rather, they are invisible.
	if(m_avoiding == 0)
	{
		orxOBJECT* player = GetObjectByName( "Player" );
		orxVECTOR playerpos;
		orxObject_GetPosition(player,&playerpos);
		
		orxObject_GetPosition(m_me,&mypos);
		
		orxVector_Sub(&difpos, &playerpos, &mypos);
		orxObject_SetRotation(m_me,atan2(difpos.fY,difpos.fX));
		float dist = orxVector_GetSize(&difpos);
		if(dist > 10)
		{
			orxVector_Normalize(&difpos,&difpos);
			orxVector_Mulf(&difpos,&difpos,80);
			orxObject_SetSpeed(m_me,&difpos);
		}else{
			orxVECTOR nullpos;
			orxVector_Set(&nullpos,0,0,0);
			orxObject_SetSpeed(m_me,&nullpos);
		}
	}else{
		m_avoiding--;
	}




	orxVECTOR difpos1;
	orxVECTOR difpos2;
	std::vector<orxOBJECT*> Enemies = GetAllObjectsByName( "Enemy" );
	for(it = Enemies.begin(); it != Enemies.end(); it++)
	{
		if((*it) == m_me)continue;
		orxVECTOR enmpos;
		orxObject_GetPosition((*it),&enmpos);
		float dist = orxVector_GetDistance(&mypos,&enmpos);
		if(dist < 32)
		{
			m_avoiding = 10;
			orxVector_Sub(&difpos1, &mypos, &enmpos);
			orxObject_SetRotation(m_me,atan2(difpos1.fY,difpos.fX));
			orxVector_Normalize(&difpos1,&difpos1);
			if(dist > 0)
			{
				orxVector_Mulf(&difpos1,&difpos1,80);
				orxObject_SetSpeed(m_me,&difpos1);
			}

			orxVector_Sub(&difpos2, &enmpos, &mypos);
			orxObject_SetRotation((*it),atan2(difpos2.fY,difpos2.fX));
			orxVector_Normalize(&difpos2,&difpos2);
			if(dist > 0)
			{
				orxVector_Mulf(&difpos2,&difpos2,80);
				orxObject_SetSpeed((*it),&difpos2);
			}

		}
	}

Comments

  • edited May 2012
    (Really quick answer)

    Try to set 0.0f on the fZ part of the vector just before setting the new speed. I'm really not sure, but if there's another value, maybe the objet will be moved out of the frustum (really not sure about this behaviour, I never tried that^^).

    But, to do some bouncing, I think the best solution is to use the physics engine provided in Orx (which is actually Box2D, Orx only has a wrapper on it). When you use it, you have nothing to do when object collision occurs ;)

    There's a tutorial to setting up correctly the physic engine (http://orx-project.org/wiki/en/orx/tutorials/physics).

    Hope that helps !
  • edited May 2012
    faistoiplaisir wrote:
    (Really quick answer)

    Try to set 0.0f on the fZ part of the vector just before setting the new speed. I'm really not sure, but if there's another value, maybe the objet will be moved out of the frustum (really not sure about this behaviour, I never tried that^^).

    But, to do some bouncing, I think the best solution is to use the physics engine provided in Orx (which is actually Box2D, Orx only has a wrapper on it). When you use it, you have nothing to do when object collision occurs ;)

    There's a tutorial to setting up correctly the physic engine (http://orx-project.org/wiki/en/orx/tutorials/physics).

    Hope that helps !

    Ah, yes, that's a good one to check at least. Don't want my critters to fly out into space.

    As for the physics engine, I've considered using it but I want some of my own behavior in there. It may also be possible to do with the physics engine, but as I've done this before without it i'd rather first replicate the results before I try something new.

    Thanks :)

    EDIT: You were right, forcing the Z down to zero fixed the problem! Thanks again!
  • edited May 2012
    As you want ;)

    But, doing some realistic collision behaviour is really difficult, and I'm completly sure that you can't have a result better than box 2D :)

    Tips: use orxLOG("none") in your code to trace the speed vector before and after your change, so you could easily see if your vector has a stupid/wrong value.
  • edited May 2012
    faistoiplaisir wrote:
    As you want ;)

    But, doing some realistic collision behaviour is really difficult, and I'm completly sure that you can't have a result better than box 2D :)

    Tips: use orxLOG("none") in your code to trace the speed vector before and after your change, so you could easily see if your vector has a stupid/wrong value.

    I'm not doing 'realistic' behavior as I'm making an arcade game. I'm not saying you are wrong, and if I was looking for (semi) realistic physics I'd definetly have used it.

    Anyway, just wait for the result aye :P
  • edited May 2012
    Another question: How do you change the Texture/AnimSet of an object?

    Tried
    			orxANIMSET* defenemy = orxAnimSet_CreateFromConfig("DefEnemyAnimSet");
    			bool tmp1 = orxObject_SetAnimSet(m_me,defenemy);
    			bool tmp2 = orxObject_SetCurrentAnim(m_me,"DefEnemyWalk");
    			bool tmp3 = orxObject_SetTargetAnim(m_me,"DefEnemyWalk");
    

    but no cigar yet.
  • edited May 2012
    Hi,

    For that, I'm not sure, I prefer don't answer something wrong.

    In that case, my method will be to open orxObject.c, search orxObject_CreateFromConfig() and look how it's done here.

    (Little remarks (but it will not solve your problem), it's better to use orxBOOL (and other orx type) instead of "bool", "float", etc).
  • edited May 2012
    faistoiplaisir wrote:
    Hi,

    For that, I'm not sure, I prefer don't answer something wrong.

    In that case, my method will be to open orxObject.c, search orxObject_CreateFromConfig() and look how it's done here.

    ha no worries, but I'll have a looksee until someone else bothers to read this
    (Little remarks (but it will not solve your problem), it's better to use orxBOOL (and other orx type) instead of "bool", "float", etc).

    Technically, in my case, it won't matter much. I'm intend to port it to IOS, which I know also uses the same bool and int types, so there will be no difference.

    However, I can imagine that this isn't always the case (reminds me of fixed point float class, don't get me started) so I'm aware that, if I want to port to anything else, your point would be more than valid.
  • edited May 2012
    Yep, you have to keep in mind that the space is still 3D when doing vector operations. :)

    As for Box2D, you can also simply use it for collision detection but not having any rigid body dynamics simulation per se by using non-solid parts.

    As for the animset, why do you want to change it at runtime instead of defining it in config (just curious)?

    As for types, yep, it's a good habit for portability (32b/64b, no FPU available, etc...), but not a requirement, of course. :)
  • edited May 2012
    iarwain wrote:
    Yep, you have to keep in mind that the space is still 3D when doing vector operations. :)
    Duely noted XD
    As for Box2D, you can also simply use it for collision detection but not having any rigid body dynamics simulation per se by using non-solid parts.
    Do you have an example of using it for collision detection then running some custom code?
    As for the animset, why do you want to change it at runtime instead of defining it in config (just curious)?
    I've got an 'enemy' and a 'defeated enemy' - I ended up solving it by simply deleting the first and creating a new object of the other; what I intended to do is change 'enemy' to show the 'defeated enemy' textures/animations.
    As for types, yep, it's a good habit for portability (32b/64b, no FPU available, etc...), but not a requirement, of course. :)
    Yeah, figured as much :P I'll keep it in mind :)
  • edited May 2012
    Gemberkoekje wrote:
    Do you have an example of using it for collision detection then running some custom code?

    Not right there, but you can take the physics tutorial for example, set the physics parts Solid property to false and listen for the orxEVENT_TYPE_PHYSICS/orxPHYSICS_EVENT_CONTACT_ADD events, you'll then get both colliding objects, the parts that collide within them, the contact position and normal. Up to you to do anything then, if you don't they'll continue their motion uninterrupted.
    I've got an 'enemy' and a 'defeated enemy' - I ended up solving it by simply deleting the first and creating a new object of the other; what I intended to do is change 'enemy' to show the 'defeated enemy' textures/animations.

    Well, in that case you should have all your enemy/defeated enemies in the same animation set (the big graph), and simply call orxObject_SetTargetAnim(MyObject, "Defeated"). That should work just fine if your animation graph (including all the links) are setup correctly.
  • edited June 2012
    We used the method iarwain suggested for our senior project game. It worked perfectly; I can show you how we did it if you want to.
Sign In or Register to comment.