playMaker

Author Topic: Gun and Raycasting  (Read 4061 times)

Loic Joint

  • Junior Playmaker
  • **
  • Posts: 76
Gun and Raycasting
« 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 !

Loic Joint

  • Junior Playmaker
  • **
  • Posts: 76
Re: Gun and Raycasting
« Reply #1 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 :



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 ?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Gun and Raycasting
« Reply #2 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

Loic Joint

  • Junior Playmaker
  • **
  • Posts: 76
Re: Gun and Raycasting
« Reply #3 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 :



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)



Or to the right...



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

Thank !
« Last Edit: November 25, 2011, 10:10:13 AM by Loic Joint »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Gun and Raycasting
« Reply #4 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

Loic Joint

  • Junior Playmaker
  • **
  • Posts: 76
Re: Gun and Raycasting
« Reply #5 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