Jump to content

Need help with math.sqrt (collision detection)

- - - - -

  • Please log in to reply
4 replies to this topic

#1
winnitbaker

winnitbaker

    Newbie

  • Members
  • Pip
  • 3 posts
I am using XNA to make a game for one assignment for my degree. I have used hit detection before in a previous game but for some reason it will just not work this time. I am not sure if it is because the one token is created in another class or something to do with the scene in the other class. Below is the code of the function. More code can be provided
cheers

public void hitDetectionRockBullet()
{

foreach(rockToken rock in lstRock)
{
WeaponBulletToken bullet = new WeaponBulletToken("bullet");


d1 = Math.Sqrt((bullet.Position.X - rock.Position.X) * (bullet.Position.X - rock.Position.X) +
(bullet.Position.Y - rock.Position.Y) * (bullet.Position.Y - rock.Position.Y));

if (d1 <= (32 + 32))
{
g_scene.Remove(rock);
lstRock.Remove(rock);
}
break;
}
}

#2
Todilo

Todilo

    Newbie

  • Members
  • Pip
  • 5 posts
I would guess that you get some wrong position data or similiar. dont see any errors in the code. Debug your application, set breakpoints and you will see the problem.

#3
winnitbaker

winnitbaker

    Newbie

  • Members
  • Pip
  • 3 posts
I think it may be the bullet token but i have tried the bullet from other class and everthing really stuck lol:crying:

---------- Post added at 07:14 PM ---------- Previous post was at 06:59 PM ----------

Ive got some hit detection but it is not consistent is there any thing wrong with the hit detection of this code

---------- Post added at 09:06 PM ---------- Previous post was at 07:14 PM ----------

SORTED it was the break in the wrong place

#4
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
When posting code, it is the user's responsibility to employ CODE tags, as noted in CodeCall's posting rule #6 (Here).

* * *

I don't know C#, and I don't really know what the problem is either, though.

#5
winnitbaker

winnitbaker

    Newbie

  • Members
  • Pip
  • 3 posts
Sorry I am new to forums i will do this from now on




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users