Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Loic Joint on November 24, 2011, 06:27:47 AM

Title: Gun and Raycasting
Post by: Loic Joint on November 24, 2011, 06:27:47 AM
Hello, (and sory for my english, I'm french).

I try to make a little tank game with a top down camera. The tank work, but now I whant to make a simple fire system : when the player click, a raycast line is draw from the face of the tank turret on a certain distance and if an enemi is detected on the line, an action is realeased on it.

I try to use "Draw Debug Ray" and "Reycast hit info" but I don't understand the fonctionnement of it.

Thank very much for your help !
Title: Re: Gun and Raycasting
Post by: Loic Joint on November 25, 2011, 06:00:42 AM
I have solved the problem, but I have another one now.

I use "Raycast" to draw a line between my tank and a object fixed under the cursor :

(http://www.naphelia.com/net/bug_forum/unitypb_1.jpg)

But the line direction is calculed with the origine point of the scene (0,0,0). (I can post a video)

Someone can help me ?
Title: Re: Gun and Raycasting
Post by: jeanfabre on November 25, 2011, 08:56:30 AM
Hi,

 Try to use either the "from gameObject" or the "From position" they might very well interfere. Don't set both of them.

 Bye,

 Jean
Title: Re: Gun and Raycasting
Post by: Loic Joint on November 25, 2011, 10:08:27 AM
Hi,

I have try to use only "from gameObject" or "from position" but nothing is changed.

A screen of the problem :

(http://www.naphelia.com/net/bug_forum/unity_pb2.jpg)

On this screen, my tank is in the center of the scene, a debug line is raycast from the turret of the tank to the mouse, all is ok.

But if I move the tank to the top (for exemple)

(http://www.naphelia.com/net/bug_forum/unity_pb3.jpg)

Or to the right...

(http://www.naphelia.com/net/bug_forum/unity_pb4.jpg)

the direction of the line is wrong...
This is a problem whith my vectors ?

Thank !
Title: Re: Gun and Raycasting
Post by: jeanfabre on November 28, 2011, 05:38:48 AM
Hi,

It seems obvious to me that the angle of the ray cast does not change as you move the tank. I think it's a problem of referencing. The ray cast use global referencing, but i bet you are giving the local reference somehow.

 Try the following:

Detach the turret from the tank. Does the ray cast the works ok as you move and rotate the turret ( using the editor tools like move and rotate)? If that's the case it is a referencing problem.

Else , don't hesitate to send me that scene, and i'll have a look and fix your problem.

 Bye,

Jean
Title: Re: Gun and Raycasting
Post by: Loic Joint on November 28, 2011, 05:50:51 AM
Hi,

Thank for your help ! I have finaly used a other system for the tank turret, a simple projectile.

Thank for the proposition of private message, if I have the same problem the next time, I will contact you.

Bye,
LOIC