playMaker

Author Topic: Add force  (Read 4551 times)

magarcan

  • Playmaker Newbie
  • *
  • Posts: 23
Add force
« on: December 10, 2012, 05:01:37 PM »
I´m working on an easy example but I don't know why, it's not working propertly. Here is my basic setup:


I have a gameobject.
I initialize a prefab, ad force to it and wait. The repeat it.

Here goes the unity package: http://www.mediafire.com/?4c9p9l6vmga5rok

The problem is that firs time appears my prefab, but then appear twice togeter, please take a look that video:

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force
« Reply #1 on: December 11, 2012, 04:52:04 AM »
Hi,

 Do you really want to create everytime a new prefab? that is likely your problem. Can you explain what you want to achieve?

bye,

 Jean

magarcan

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Add force
« Reply #2 on: December 11, 2012, 05:30:30 AM »
Hi!

What I want to do is create a new instance of my existing prefab... I've seen scripts that uses clone or instantiate.

It was supposed to be the base for a machine-gun  :-\

Cheers!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force
« Reply #3 on: December 11, 2012, 05:33:01 AM »
Hi,

 Then this is what you need. I am not sure then where is your problem. Tho for efficiency, I would look into using particles for your machine gun bullets and maybe use a raycast to know if you are hitting a target. depending on the firing rate, you will kill performances by spawning a new prefab for every bullets ( you could use a pool manager for this, but that would not solved everything).

bye,

 Jean

magarcan

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Add force
« Reply #4 on: December 13, 2012, 06:40:22 AM »
Hi!

I solved the problem, because I gonna need that for some weapons...

I've been trying to implement what you said using Raycast, but I'm going in circle (I've been trying to do it by myself before asking again). Do you know if are there any samples related in the forum? I've been taking a look but not found anything.

I think I show an example of a robot firing but I've no idea where...

Cheers!!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force
« Reply #5 on: December 13, 2012, 08:18:26 AM »
Hi,

 I don't know any examples of that kind no. But from your post, I am still unsure where you are actually having problems?


bye,

 Jean

magarcan

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Add force
« Reply #6 on: December 13, 2012, 08:37:29 AM »

I'm trying to convert from this basic script:
Code: [Select]
function RayShoot(){

var hit : RaycastHit;
var direction = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position , direction * Range , Color.blue);
if(Physics.Raycast(transform.position , direction , hit, Range)){
if(hit.rigidbody){
hit.rigidbody.AddForceAtPosition( direction * Force , hit.point);
}
}
}

The problem is that when I arrive to the Check Rig body state, the variable objectHited is null.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force
« Reply #7 on: December 13, 2012, 08:45:02 AM »
Hi,

 Is the variable "didHit" true? if it is true and "objectHited" then there is a big or something wrong, else, it's likely that you are not raycasting where you think it does or not far enough, or the target you would like to hit doesn't have a collider or something like that.

bye,

 Jean

magarcan

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Add force
« Reply #8 on: December 13, 2012, 09:13:30 AM »
It's rare, because if I don't play any action in the Check Rigid body state null reference error doesn't appear...

Please take a look:

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Add force
« Reply #9 on: December 14, 2012, 05:50:07 AM »
Hi,

 yes, it's simply because your objecthited is void and the "hasComponent" action do not take that in consideration.

 A: you should check that objectHited it not void somehow ( either with the raycast event or the bool or simply check that variable itself)

OR:
 B: Would you prefer a modified "HasComponent" to not fire error? While it's feasible, maybe this is not a good idea to fail silently, it would hide something that you should be aware of within your process.

bye,

 Jean