Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
fpsarmedunity

My work so far ..help with collsion

Question

Hi here a video of my  test  work to try some gameplay mechanics.. i used free fpskit as base template expanded over time ( thaks to OMA and TheMars over all others..they know why LOL).I have some other gameplay functions in place and are only waiiting to be added to the main template..

 

 

btw i have and issue with drag items since i noticed that picked up items colllsion work fine  until i pick and item into inventory( like weapons ,ammo, consumables) but if i eventually drop picked up items from inventory and try to drag item again collsion with static mesh collsion and with scene doesnt work anymore  when player held item... any hint

  • Like 1

Share this post


Link to post
Share on other sites

28 answers to this question

Recommended Posts

  • 1
Please login or register to see this quote.

1) create a new script and add it to the Player Obeject and/or Prefab in scene 

2) write this into the script: 

Please login or register to see this code.

3) drag n drop "No Weapon" into the the grabobjects slot of that script

4) the new Pickable Script should look like this: 

Please login or register to see this code.

5) test it ... not sure if that will work but i think that was the problem 

6) mark this as best answer ;) (if it works, else call me stupid or sth. ) 

  • Like 1

Share this post


Link to post
Share on other sites

  • 1

nope  i got this error

 NullReferenceException: Object reference not set to an instance of an object
Pickable.OnTriggerEnter (UnityEngine.Collider otherCollider) (at Assets/_Resources/Scripts/Pickable.cs:39)

 

for every object that  have pickable scirpt

Share this post


Link to post
Share on other sites
  • 1
Please login or register to see this quote.

yes, it should but i think this gets optimized at compile time to what i wrote anyways so its the same just easier to read when you leave that away 

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

can you make a video of the issue? 

It looks like the collider is only on the gameobject in scene but not on the prefab you instantiate when you drop sth. ? 

or there is something different going on, do you change the collider in script at some point? like set it to a trigger or deactivating it? 

 

Share this post


Link to post
Share on other sites
  • 0

hi and thanks for your reply.. i'll do a video to show the exact issue  when i'll come back to home this evening and can try the template

and i'll post the scirpt too btw pickup script on object has two colliders one classic collider and another set to trigger to check the interaction system..and i cheked yesterday if i remeber correcly but i think instantiated prefab when drop as both colliders too

Share this post


Link to post
Share on other sites
  • 0

HI  AGAIN i got the  cause of the issue

Please login or register to see this link.

 

 

pratically the pickup script for weapons ,consumables and so on has a reference for  the no weapon gameobject of the player ..whwn i start the scene the Noweapon gameoject is correcly referenced in the pickup script but when play pickup object and after drop again on scene NoWeapon Gameobejctis not referenced into the pickup script anymore..

 

I tried to create a prefab of the NoWeapon gamobject 

Please login or register to see this link.

 

to put as reference in the object to picked up prefab (in this case canned food) but doesnt work

 

ant hint about that??

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

dont quite get it or how this can happen 😕  but i think that creating a prefab is not really the way to go here, check why it even got dereferenced? 

 

  • Like 1

Share this post


Link to post
Share on other sites
  • 0

So the grabobjects variable is dereferencing the noobject gameobject correct? The only way that is possible is if somewhere in your code your either replacing it with something else or telling it to = null. The answer lies in your code. Just open your code and search for grabObjects = and that is where your issue is. Unless your talking about dereferencing After play mode has stopped and in that case, play mode changes do not affect edit mode

  • Like 2

Share this post


Link to post
Share on other sites
  • 0

yes but o have to script referenced in my Pickup Script Notepickup script ( that is a canvas gameobjct) and the GrabObject Script taht is held by the  NoWeapo Gameobject(child of the player gameobject)

 

the notepickup works correcly even after player pickup and drop the object but the GrabObjects not but i noticed that if I replace on runtime manually the reference to to Noweapon (help by the player) all works as expected.. so how can i reference direclty to the Nowepaon Gameobject?

as you can seed in the video

 

 

here my pickable script

Please login or register to see this code.

 

 

and here my GrabObjects Script

 

Please login or register to see this code.

 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this code.

yeah, i think i got it, try this! I hope i dednt mess shit up since i edited that in the browser ^^

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

ah damn i fucked that up ^^ its on the noweapon not on the player right? 

So do you have any component that accesses that game object directly on the player?

If not it might actually be the best to create one to be able to access it.

like: 

public class Helper : MonoBehaviour{

     public GrabObjects grabLogic;

}

sth. lke that and drop it on the player, then change the line in Start() where it assigns grabObjects to this: 

Please login or register to see this code.

i know this is not very elegant but should do the trick :) if not ill download the kit and try to fix it there 😛

edit: make sure that you asign the NoWeapon to grabLogic (unity will grab the correct component automatically)  

edit2: idk why this is all red this is not on purpose but im on mobile and too lazy to change color ^^ no meaning behind that

Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0

yes many thanks after I replied to you i tried exactly wahat you wrote in your last post  and it worked..

 

many thanks.. 

i need t o make some test  but  it seems t owork even i i left this

 

 

Please login or register to see this code.

btw only for asking why did you modifed te lines to 

 

Please login or register to see this code.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

ah.. ok understood.... btw it works like a charm.... many many many thanks

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

ah.. ok understood.... btw it works like a charm.... many many many thanks

only one last  question..

 as you can see from my grabobkect script  i use adjust float to set distance for grabbed object form player/camera but i noticed that if i set the adjust distance to 1 for e.g. when player pickup object , picked up object became inactive after held by the player and player cannot remove o push the object away...  what could be the problem??

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

but there are values of adjust that work? 

most likely nothing to do with adjust but rather disabeling something when you pick up that doesnt get enabled again when you drop or sth. like that.

Im actually sorry i couldnt spot sth. at first sight... also  im not quite positive if i got you correctly ... i know its annoying but a video of the issue really helps me understand things :))

also i have sth. to do right now but will get back later :)

 

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

here the video

 

as you can see thre default adjust distance is set to 2,5 and all works fine but i want a nearest distance for the object when is picKed up by the player but  when i set a near distance like 1, or 1,5 object after picked up freeze on player "hands" and cannot be pushed away but only rotated  ,after if i set again a far adjust distance object can be dragged and moved again.. i think is due to de fact that when obejct is near to the player maybe it inteferes with it and something is disabled but i cannot figured what

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

ah i see lol ^^ i think it got stuck in the collider of the player? 

cant rembre exactly but there was a way you can set up masks for the collision, just know that if you do that you will also be able to walk through it. 

But this is the only thing that comes to my mind... 

or well you could ignore player collisions until you hit something other than the player and than enable them again... 

But really i would just set it to where it works fine and dont worry too much about it, just keep it in mind for big objects so you can set teir pivot accordingly etc. 

 

Edit: after watching again it lookes like sth. else is going on since the grab time increases but i honestly cant tell you why im sry. 

Might be cheking your script again later... maybe some conditon where you have to hit the player or other collider causes this.

 

Edited by Erarnitox

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

nope id not the collision mask since i tried yet .. i excluded player from collision with pickup layer( the layer of pickubles)  but when i set a near held distance  the problem  remain so i dont think is something related to the player collider..

 

i apologize i i steal your time but  ask only for one last question maybe you have a good hint for me..

as you can see in this video i have a little bug i cannot figgured out  so when player approach to a only pickable object the pickup icon correcly appear on screen but when player  have a weapon in hand it is supposed to disappear but insted it remain onscreen evne when player has a weapon in his hands..

 

the affected code for this system is this

Please login or register to see this code.

and is the last part of the GrabObjects script you saw above

 

do you think is solveable?

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

yeah is solveable :) should work if you do sth. like this: 

Please login or register to see this code.

hope that works not too sure tho. 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

error on compile

Assets/_Resources/Scripts/GrabObjects.cs(212,24): error CS1525: Unexpected symbol `.', expecting `,', `;', or `='
 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

double click it? ^^ looks like a syntax error so yeah a missing ; or sth. like that .... just check out whats missing i dont know what code is at that line 

 

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

from where does this method get called and also when does it get called? 

calling it once after every weapon switch should fix it, right? 

 also where is the component placed? if its on the no weapon object it cant run once the object is deactivated

Edited by Erarnitox

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...