Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Help with raycasting and arrays!

Author
Message
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 18th Sep 2009 21:24 Edited at: 18th Sep 2009 21:25
Hi, I am attempting to use the "SC_Raycast" command as a sub for shooting an actual object.

Here is my problem: I can return an object number for a cube I create, but, when I setup my enemy objects (which I use arrays for) raycast will not return on object number other than a really large number starting with 7. EDIT: The number that starts with 7 seems to return if nothing is intersected.

Here's my code for setting up my enemy objects:



This code sets up a basic cube:



When I "shoot" or create a ray that intersects the above cube it returns the number "110" But I cannot return a number for the enemies when I "shoot" them. Here's my raycast code:



Does anyone have any ideas?? I'm guessing that the problem is because my enemies are created as arrays, but I don't have any clue how to fix this. I will post all my code if you guys want.

Thanks a lot!

ßõw§€r¥¤
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 18th Sep 2009 23:50
Okay, I've figured out that the reason the ray_cast isn't working is because I am positioning them through arrays like this:



I also have them moving around using the "e...next e" similarly to the way I randomize there positions. But for some reason, Sparkys collisions isn't recognizing that they are moving. I've found that if I aim at position 0,0,0 and shoot, it will return the number of my last created enemy (object 20). But that actual enemy is moving around somewhere else.
>>>>>
So my question is, how do I get Sparkys collisions to recognize my enemies position through arrays? Or is it not possible?

ßõw§€r¥¤
z_man
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: Australia
Posted: 19th Sep 2009 03:24 Edited at: 19th Sep 2009 03:26
After repositioning/rotating an object, you need to use "SC_UpdateObject" to update the collision representation of the object.

EDIT: Also, in the code above, I'm assuming obj 45 is the player object?

-Z

BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 19th Sep 2009 07:05 Edited at: 19th Sep 2009 07:07
Okay, I will give that a shot!

I use two objects to cast the ray, the player object, and a reference object (object 45) that is placed 10,000 units away from the camera, in the direction your looking. I then cast a ray between the two positions. For some reason, it's still not picking up the enemies

It does seemed to have moved the collisions somewhere else though, as when I aim at point 0,0; it doesnt return a collision with object 20. I'm stumped!!

Please can you help me fix this? Thanks!

EDIT: (Note: As I stated above, it does with work a stationary cube that I made if I setup the cube. But it won't see the enemy objects...

ßõw§€r¥¤
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 19th Sep 2009 14:47 Edited at: 19th Sep 2009 14:47

is all very well, but where are you setting

Raycasting works to the actual position, not some numbers you have stored in an array that you haven't used yet.

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
BowserYo
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location:
Posted: 19th Sep 2009 19:06
Okay, are you asking where I am actually moving the enemies? If so:



Near the end of that code, I update all my enemy objects, but that doesn't seem to work. I'm not quite understanding what you are saying though

ßõw§€r¥¤

Login to post a reply

Server time is: 2024-11-24 01:59:05
Your offset time is: 2024-11-24 01:59:05